multiprocessing and events

I was attempting to convert my threaded application to use the
multiprocessing module (as a short educational exercise) and found that my
registered events didn't correctly make it back to the GUI. The child
process started up correctly, but nothing made it back to the parent. I
haven't been able to find any information on why this might/might not work,
does anyone have insight? or how to work around it?

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/multiprocessing-and-events-tp5713340.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Hi,

I was attempting to convert my threaded application to use the
multiprocessing module (as a short educational exercise) and found that my
registered events didn't correctly make it back to the GUI. The child
process started up correctly, but nothing made it back to the parent. I
haven't been able to find any information on why this might/might not work,
does anyone have insight? or how to work around it?

By 'events' you mean wx events right, and that you are trying to
PostEvent from another process?

Threads share the same memory space withing the same process, where as
multiprocess will create a new process with its own memory space.
Events in wx are all go through the instance of the wxApp in the given
process. They will not work as an IPC mechanism between different
processes.

You will need to make use of some of the inter-process communication
that the mulitprocess module provides or other means (i.e sockets,
...) to get your messages back to the UI process and then either
translate them in to events or use some other callback mechanism such
as pubsub to trigger the action.

Cody

···

On Fri, May 25, 2012 at 4:22 PM, soulcmdc <soulcmdc@gmail.com> wrote:

By "registered events didn't correctly make it back to the GUI" do you mean things that you've sent via wx.PostEvent, wx.CallAfter, etc? If so then it's because the instances of those things that you are calling are in the child process, and they have no clue that you are running in a multiprocessing environment, and so they are in effect trying to send events to the GUI in the child process, which doesn't really exist. You should instead be using one of the methods provided by multiprocessing (like Queue or Pipe) to communicate back to the parent process, or some other IPC mechanism.

···

On 5/25/12 2:22 PM, soulcmdc wrote:

I was attempting to convert my threaded application to use the
multiprocessing module (as a short educational exercise) and found that my
registered events didn't correctly make it back to the GUI. The child
process started up correctly, but nothing made it back to the parent. I
haven't been able to find any information on why this might/might not work,
does anyone have insight? or how to work around it?

--
Robin Dunn
Software Craftsman

Correct, I was using wx.PostEvent.

I'm using Queue for communication, but was using wx.PostEvent to ask the GUI
to go check the queue. How would I go about getting the a wxPython GUI to
read from the queue without using events? In other child processes that
need to wait for input, I've been using a while loop that checks the queue
periodically, but I don't know how to get the wxPython MainLoop to do the
same thing.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/multiprocessing-and-events-tp5713340p5713368.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Correct, I was using wx.PostEvent.

I'm using Queue for communication, but was using wx.PostEvent to ask the GUI
to go check the queue. How would I go about getting the a wxPython GUI to
read from the queue without using events?

you should be able to use wx.PostEvent in the process that the GUI is
running in (started from). You jsut can't expect an event posted from
oen process to be picked up in another process -- you need to use the
queue for that.

Are you actually running a GUI in multiple processes? I'd be
interested to know how well that works.

In other child processes that
need to wait for input, I've been using a while loop that checks the queue
periodically, but I don't know how to get the wxPython MainLoop to do the
same thing.

you could use a wx.Timer to poll the queue -- if that's what you're asking.

-Chris

···

On Wed, May 30, 2012 at 10:38 AM, soulcmdc <soulcmdc@gmail.com> wrote:

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/multiprocessing-and-events-tp5713340p5713368.html
Sent from the wxPython-users mailing list archive at Nabble.com.

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Or have a thread in the GUI process that waits on the queue, and then when it gets a queue item use wx.PostEvent or wx.CallAfter to pass it on to the GUI thread.

···

On 6/1/12 9:50 AM, Chris Barker wrote:

On Wed, May 30, 2012 at 10:38 AM, soulcmdc<soulcmdc@gmail.com> wrote:

Correct, I was using wx.PostEvent.

I'm using Queue for communication, but was using wx.PostEvent to ask the GUI
to go check the queue. How would I go about getting the a wxPython GUI to
read from the queue without using events?

you should be able to use wx.PostEvent in the process that the GUI is
running in (started from). You jsut can't expect an event posted from
oen process to be picked up in another process -- you need to use the
queue for that.

Are you actually running a GUI in multiple processes? I'd be
interested to know how well that works.

  In other child processes that
need to wait for input, I've been using a while loop that checks the queue
periodically, but I don't know how to get the wxPython MainLoop to do the
same thing.

you could use a wx.Timer to poll the queue -- if that's what you're asking.

--
Robin Dunn
Software Craftsman