[Twisted-Python] Using wxreactor on Windows

Joshua Ritter jritter at bektel.com
Wed Oct 6 13:23:56 EDT 2004

On Windows, I was having a problem with my wxreactor application
intermittently freezing on initialization.  It was also taking a long time
to exit.

wxdemo.py doesn't exhibit the problem at startup, most likely due to the
simplicity of the GUI.  The demo does however exhibit the exit problem.

What I did to alleviate both problems was to move the timer creation and
starting code:

class MoMWorldServer(wx.App):
    def OnInit(self):

    def OnFirstIdle(self,evt):
        #We catch the first idle message and use it to kick start
        #the twisted reactor, this avoids a possible deadlock, at least on
Windows, gulp
        print "Starting Network Service"

        wx.EVT_IDLE(self,None) #remove handler

        #create the timer and start it
        reactor.timer = wxreactor.ReactorTimer(reactor)

For the exiting problem, I stop the timer on the close event to the main
frame of the application:

class MainFrame(wx.Frame):
    def __init__(self, parent, id, title):

      def OnClose(self,evt):
        #stop the timer here

-Josh Ritter
Technical Director

More information about the Twisted-Python mailing list