[Twisted-Python] wxPython locking the event processing?

Philippe Lafoucrière lafou at wanadoo.fr
Sat Jul 5 05:29:06 EDT 2003

On Sat, 2003-07-05 at 10:52, Patrik Blommaskog wrote:
> Hi list,
> Using Twisted/wxPython/Win2k, it seems to me like Twisted's event processing
> gets locked up while I'm moving around in a menu (without selecting
> anyting). For example, if there is a callLater() pending, but the menu bar
> is activated when the time occurs, the call is not made until I leave the
> menu.
> The problem is easily demonstrated with the Twisted wxPython demo found at:
> 	http://twistedmatrix.com/documents/examples/wxdemo.py
> Start the app, then click on the "File" menu. Don't select anything, just
> leave the menu there. Now, the output to stdout is suspended. Release the
> menu and the output resumes.
> Now, I would really like for my model to keep working in the background
> while I'm moving around in the GUI.
> Any suggestions?
> - Patrik

try this

from wxPython.wx import *

#~ if sys.platform == 'win32':
    #~ from twisted.internet import win32eventreactor
    #~ win32eventreactor.install()

from twisted.internet import reactor
from twisted.python import threadable
import threading

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

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

ID_EXIT  = 101

class MyFrame(wxFrame):
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title, wxDefaultPosition,
wxSize(300, 200))
        menu = wxMenu()
        menu.Append(ID_EXIT, "E&xit", "Terminate the program")
        menuBar = wxMenuBar()
        menuBar.Append(menu, "&File");
        EVT_MENU(self, ID_EXIT,  self.DoExit)
        EVT_CLOSE(self, self.OnCloseWindow)
        self.text = wxTextCtrl(self, -1, "Text\n", style=wxTE_MULTILINE)
        reactor.callLater(0, self.twistedCallsMe, 0)
    def DoExit(self, event):

    def OnCloseWindow(self, event):
    def twistedCallsMe(self, count):
        print count
        self.text.AppendText('%d\r\n' % count)
        reactor.callLater(0.5, self.twistedCallsMe, count + 1)
class MyApp(wxApp):
    def OnInit(self):
        # Do whatever you need to do here
        self.frame = MyFrame(NULL, -1, "Hello, world")
        return true

def demo():
    app = MyApp(0)

if __name__ == '__main__':

More information about the Twisted-Python mailing list