[Tutor] Is it thread safe to collect data from threads where run has finished?

Wesley Brooks wesbrooks at gmail.com
Sat Nov 1 13:04:33 CET 2008

Dear Users,

I've got a few tasks that block for a while and cause my wxPython interface
to lock up while they process. I'm thinking about migrating these to threads
which I kick off when I want the task done. In the run bit of the thread the
main work will be done, it will store the information as part of the object
and when done post an event to the user interface for it to collect of the
information and dispose of the thread.

So there'll be a part of a wx event that looks something like:

*self.loadThread = FileLoadThread(fileName, doneEvent)
The FileLoadThread object would look like:

*class FileLoadThread(threading.Thread):
    def __init__(self, mainGUI, fName, doneEvent):
        self.mainGUI = mainGUI
        self.fName = fName
        self.event = doneEvent

    def run(self):
        self.dataObject = self.LoadFile(fName)
        wx.PostEvent(mainGUI, doneEvent)*

...where doneEvent is a custom event that signals to the user interface that
it can collect the dataObject by doing the following:

*self.dataObject = self.loadThread.dataObject*
*del self.loadThread*

Is this the best way to do this or should I just attach the dataObject to
the event? Is the use of wx.PostEvent thread safe?

Thanks in advance of any advice,

Wesley Brooks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081101/31986ced/attachment.htm>

More information about the Tutor mailing list