[Twisted-Python] wxPython locking the event processing?

Chris Liechti cliechti at gmx.net
Sat Jul 5 18:20:38 EDT 2003

Patrik Blommaskog wrote:
> I´ve got my app working now with the threading method that Philippe
> suggested. 

it was me that originaly posted that code on this list. and have to say 
that it contains a minor bug. startRunning must be called in the same 
thread as as twisted.mainloop will (otherwise, some nasty things will 
happen, like callFromThread() or stop() not working without an external 
just calling "reactor.run()" in a thread will fail because of the signal 
handlers have to be installed in the main thread, thus these have to be 
the stop function can also be improved, so that it does not fail when 
it's called more than once. (wxYield does not like recursive calls to 
itself ;-)

def startTwistedAndWx(app):
     """Start twisteds mainloop it its own thread,
     run the wx mainloop in the main thread"""
     global twistedthread, twistedrunning, twistedapp
     twistedapp = app
     twistedthread = threading.Thread(
     twistedrunning = 1

def stopTwisted():
     """stop the twisted thread, wx still runs"""
     global twistedthread, twistedrunning
     if twistedrunning:
         twistedrunning = 0
         #wait until reactor has shut down
         while twistedthread.isAlive():

More information about the Twisted-Python mailing list