using wxpython with non-GUI applications

Aaron Brady wrote:

Could you do multiple PyApp objects()?

app1= wx.pySimpleApp()
app2= wx.pySimpleApp()

app1.MainLoop()
#stuff
app2.MainLoop()

This works:

import wx

def th1():
  app= wx.PySimpleApp()
  fra= wx.Frame( None )
  fra.Show()
  app.MainLoop()

th1()

This doesn't:

import wx
import threading

def th1():
  app= wx.PySimpleApp()
  fra= wx.Frame( None )
  fra.Show()
  app.MainLoop()

ths= [ threading.Thread( target= th1 ) for _ in range(2) ]
[ th.start() for th in ths ]
[ th.join() for th in ths ]

You can only have a single wx.App object at a time, and whichever thread created the app object is the one that wx considers to be the main gui therad, for the life of the process. IOW, only one thread can be the one that is able to make app objects.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Thursday, January 10, 2008 1:57 PM
You can only have a single wx.App object at a time, and whichever thread
created the app object is the one that wx considers to be the main gui
therad, for the life of the process. IOW, only one thread can be the
one that is able to make app objects.

Strictly speaking incorrect.

You can only have a single wx.App object at a time.

True.

[W]hichever thread created the app object is the one that
wx considers to be the main gui therad, for the life of the process.

False. You can create wx.App objects anywhere, but they're stuck there.

Example. -This works.

import wx

def th():
  app= wx.PySimpleApp()
  frame= wx.Frame( None )
  frame.Show()
  app.MainLoop()
th()

import threading
th= threading.Thread( target= th )
th.start()
th.join()

-This doesn't.

import wx

def th():
  app= wx.PySimpleApp()
  frame= wx.Frame( None )
  frame.Show()
  app.MainLoop()
th()

import threading
th1= threading.Thread( target= th )
th2= threading.Thread( target= th )
th1.start()
th2.start()
th1.join()
th2.join()

···

-----Original Message-----