views:

172

answers:

2

Hello everyone,

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 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!

A: 

wx.CallAfter(function)

Steven Sproat
Where this should be placed to? Inside do_update() method of the dbob object? What about function arg?
wxpydon
As far as I can see, CallAfter will help me run a function after the process work, but what I want is to get some text messages during this work.
wxpydon
+1  A: 

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.

wxpydon