Dear Users,<br><br>I&#39;ve got a few tasks that block for a while and cause my wxPython interface to lock up while they process. I&#39;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.<br>
<br>So there&#39;ll be a part of a wx event that looks something like:<br><br><i>self.loadThread = FileLoadThread(fileName, doneEvent)<br>self.loadThread.start()<br></i><br>The FileLoadThread object would look like:<br><br>
<i>class FileLoadThread(threading.Thread):<br>&nbsp;&nbsp;&nbsp; def __init__(self, mainGUI, fName, doneEvent):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.mainGUI = mainGUI<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.fName = fName<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.event = doneEvent<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; threading.Thread.__init__(self)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def run(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.dataObject = self.LoadFile(fName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wx.PostEvent(mainGUI, doneEvent)</i><br>&nbsp;<br>...where doneEvent is a custom event that signals to the user interface that it can collect the dataObject by doing the following:<br>
<br><i>self.dataObject = self.loadThread.dataObject</i><br><i>del self.loadThread</i><br><br>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?<br>
<br>Thanks in advance of any advice,<br><br>Wesley Brooks<br>