Apparently so - try the appended code. However, creating new GUI elements in the child process causes a segfault on my Mac. I didn’t try doing anything else with the app. Anyway, in my experience (on Mac and Linux - I don’t do Windows) having that forked wx.App hanging around doesn’t cause any problems, and the child process still exits when the target function is finished. In one of the non-graphical modules I use the multiprocessing module independently for some “embarrassingly parallel” calculations, so the GUI is forking a process which then forks as many more as I want (i.e. # of CPUs), and this all seems to work too without weird side effects. (The drawback to doing it this way is that if the GUI crashes or freezes, all of the calculations crash too, so I also have an option of using subprocess instead, albeit with less interactivity. But all of the GUI stuff is still happening in a single process.)
-Nat
import wx
import multiprocessing
def child_process () :
app = wx.GetApp()
print type(app)
def child_process2 () :
app = wx.GetApp()
frame2 = wx.Frame(None, -1, “Hello again!”)
panel2 = wx.Panel(frame2, -1, size=(640,480))
txt2 = wx.StaticText(panel2, -1, “Hello again!”, pos=(200,200))
frame2.Fit()
frame2.Show()
def OnStartProcess (evt) :
p = multiprocessing.Process(target=child_process)
p.start()
print “Process started”
def OnStartProcess2 (evt) :
p = multiprocessing.Process(target=child_process2)
p.start()
print “Process 2 started”
if name == “main” :
app = wx.App(0)
frame = wx.Frame(None, -1, “Hello, world!”)
panel = wx.Panel(frame, -1, size=(640,480))
txt = wx.StaticText(panel, -1, “Hello, world!”, pos=(200,200))
btn = wx.Button(panel, -1, “Start process”, pos=(200,240))
btn2 = wx.Button(panel, -1, “Start process with frame”, pos=(200,280))
frame.Bind(wx.EVT_BUTTON, OnStartProcess, btn)
frame.Bind(wx.EVT_BUTTON, OnStartProcess2, btn2)
frame.Fit()
frame.Show()
app.MainLoop()
···
On Tue, Apr 27, 2010 at 10:00 AM, cool-RR cool-rr@cool-rr.com wrote:
But wait, I do use the multiprocessing module a lot for doing non-graphical tasks, but from the wxPython GUI. Does that mean that when I do it on Linux, it will fork and clone the App?
–
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en