[Tutor] Is it thread safe to collect data from threads where run has finished?
wesbrooks at gmail.com
Sat Nov 1 13:04:33 CET 2008
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:
def __init__(self, mainGUI, fName, doneEvent):
self.mainGUI = mainGUI
self.fName = fName
self.event = doneEvent
self.dataObject = self.LoadFile(fName)
...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*
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,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor