[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):
        #SNIP
        wx.EVT_IDLE(self,self.OnFirstIdle)

    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)
        reactor.timer.Start(1)

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):
        #SNIP
        wx.EVT_CLOSE(self,self.OnClose)

      def OnClose(self,evt):
        evt.Skip()
        #stop the timer here
        reactor.timer.Stop()

-Josh Ritter
Technical Director
http://www.prairiegames.com









More information about the Twisted-Python mailing list