This simple example works, but I'm worried about things happening
behind the scenes that could cause unexpected behavior in a large
application (e.g. will wx.GetApp() return the correct instance?).
By the way, I did search this group and found a discussion that hinted
that it might be OK, but no definitive answer was found.
Is there any reason something like this could cause problems?
import wx
app1 = wx.PySimpleApp()
frame = wx.Frame(None, title=‘App One’)
frame.Show()
app1.MainLoop()
app1.Destroy()
app2 = wx.PySimpleApp()
frame = wx.Frame(None, title=‘App Two’)
frame.Show()
app2.MainLoop()
app2.Destroy()
This simple example works, but I’m worried about things happening
behind the scenes that could cause unexpected behavior in a large
application (e.g. will wx.GetApp() return the correct instance?).
By the way, I did search this group and found a discussion that hinted
that it might be OK, but no definitive answer was found.
Caleb
It is my understanding that you cannot have two App objects in the same process at the same time. So, as long as you destroy one before you create the other, you should be alright. You can always create a separate App object if you put it in a separate process, of course.
I usually tell people that it is best if you don't have more than one app object in any one process (simultaneous or not) because there are various things in the library that get initialized when the app is created, and so doing that more than once could cause some problems. That said, it may be more accurate to just say that having more than one app object is not supported and behavior is undefined, but it isn't guaranteed to always fail. There may be certain situations where it is okay.
···
On 2/28/10 11:18 AM, Const wrote:
Is there any reason something like this could cause problems?
This simple example works, but I'm worried about things happening
behind the scenes that could cause unexpected behavior in a large
application (e.g. will wx.GetApp() return the correct instance?).
Too bad. Maybe I can use the multiprocessing module to launch the
first app.
Thanks,
Caleb
···
On Mar 1, 6:02 pm, Robin Dunn <ro...@alldunn.com> wrote:
I usually tell people that it is best if you don't have more than one
app object in any one process (simultaneous or not) because there are
various things in the library that get initialized when the app is
created, and so doing that more than once could cause some problems.
That said, it may be more accurate to just say that having more than one
app object is not supported and behavior is undefined, but it isn't
guaranteed to always fail. There may be certain situations where it is
okay.