Python/wxPython: Doing work continuously in the background Python/wxPython: Doing work continuously in the background multithreading multithreading

Python/wxPython: Doing work continuously in the background


I would use a threading.Thread to run the code in the background and wx.CallAfter to post updates to my window thread to render them to the user.

thread = threading.Thread(target=self.do_work)thread.setDaemon(True)thread.start()...def do_work(self):    # processing code here    while processing:        # do stuff        wx.CallAfter(self.update_view, args, kwargs)def update_view(self, args):    # do stuff with args    # since wx.CallAfter was used, it's safe to do GUI stuff here


There's a fair bit of info on the wxPython wiki about long running tasks that might be useful. They basically make use a thread and wx.PostEvent to handle communication between the thread and the main wx event loop.


Launch a new process to render in background and periodically check to see if it has returned.

You can find the documentation for the subprocess module here and the multiprocess module here. As Jay said, multiprocess is probably better if you're using Python 2.6. That said, I don't think there would be any performance difference between the two. Multiprocess just seems to be a wrapper around subprocess making certain things easier to do.

While subprocess/multiprocess is the standard way to do this, you may also want to take a look at Parallel Python.