开发者

wxpython GUI and multiprocessing - how to send data back from the long running process

Trying to run a time consuming task from a wxpython GUI. The basic idea is to start the long time task from the GUI (pressing a button) and then, a static text on the dialog should be updated from it.

First I tried some threading (http://wiki.wxpython.org/LongRunningTasks and many other resourses seen), and I want to show back the messages using Publisher.class. It didn't went so well, after a message or two, the GUI seems to frozen.

Now I want to achieve that 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开发者_C百科 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 what sets the static text on dialog.

Question is: how can I send back some text messages from this Process (just simple text, that's all I need) Thanks guys!


Robin Dunn kindly answered me in wxpython mailing list

The pubsub module is not able to cross process boundaries. You'll need to use the classes provided by the multiprocessing module, or some other inter-process communication method, to communicate between the parent and child processes.

So I fixed my issue using threading module.


The standard way is to use one or more Queue objects to pass data back and forth to a multithreading.Process. It works more or less the same way with threading.

Here is an example: http://wiki.wxpython.org/MultiProcessing


wx.CallAfter(function)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜