Wxpython GUI and multiprocessing - how to send data from a long process
Trying to run a cumbersome task from the wxpython GUI. The basic idea is to start a long running task from the GUI (click a button) and then the static text in the dialog should be updated.
I tried some streams first ( http://wiki.wxpython.org/LongRunningTasks and many other resources found) and I want to show posts using Publisher. class. It didn't go so well, after a post or two, the GUI feels frozen.
Now I want to achieve this with multiprocessing. I have this method inside my "GUI" class:
def do_update(self, e):
self.txt_updatemsg.SetLabel("Don't stop this \n")
...
pub = Publisher() # i tried also calling directly from dbob object
# Publisher() is a singleton so this must be useless?
pub.subscribe(self.__update_txt_message, ('updatedlg', 'message'))
dbob = dbutils.DBUtils() # DBUtils is the class with 'long time' tasks
dbob.publisher = pub
p = Process(target=self.do_update_process, args=(dbob,))
p.start()
while p.is_alive:
wx.Yield
def do_update_process(self, dbob):
dbob.do_update()
__ update_txt_message is a simple function that sets static text in a dialog box.
Question: how can I send some text messages from this process (just plain text is all I need) Thanks guys!
a source to share
Robin Dunn kindly answered me on the wxpython mailing list
The pubsub module cannot cross process boundaries. You will need to use the classes provided by the multiprocessing module or some other interprocess communication method for communication between parent and child processes.
So I fixed my problem with the streaming module.
a source to share
The standard way is to use one or more Queue objects to pass data back and forth in multithreading. Process. It works more or less exactly the same way as threads.
Here's an example: http://wiki.wxpython.org/MultiProcessing
a source to share