[Twisted-Python] Threading traceback

Uwe C. Schroeder uwe at oss4u.com
Wed Mar 30 14:02:07 EST 2005

Hi everyone,

I'm using twisted in a thread together with wxPython. 
Everything works quite fine, but I'm getting a strange traceback when I exit 
the application.
here's the scenario:

wx runs in the main thread
twisted runs in a secondary thread which is started like:

        _daemon = DaemonLoop(self,self._port)

where Daemonloop is (partial):
class DaemonLoop(threading.Thread,pb.Referenceable):
        def __init__(self, wxEvtHandler, port):
            super(DaemonLoop, self).__init__()
            self.ui = UIProxy(wxEvtHandler)

        def _error(self,error):
	    if self.ui:
        def run(self):
	    # Run reactor

	def stop(self):

        def connectionLost(self):

I stop the application from the main thread using

_daemon.stop() <- should kill the twisted reactor
wx.Exit() <- kills the main thread

The app exits (on linux), but I get this traceback:

Unhandled exception in thread started by <bound method DaemonLoop.__bootstrap 
of <DaemonLoop(Thread-1, stopped daemon)>>
Traceback (most recent call last):
  File "/usr/lib/python2.3/threading.py", line 451, in __bootstrap
  File "/usr/lib/python2.3/threading.py", line 460, in __stop
  File "/usr/lib/python2.3/threading.py", line 256, in notifyAll
  File "/usr/lib/python2.3/threading.py", line 238, in notify
    currentThread() # for side-effect
TypeError: 'NoneType' object is not callable

The problem seems to be on windows. There the app doesn't exit all the time, 
just sometimes. On Win the window disappears, but in the process list is 
still the application process.
So this looks to me like there are still non daemon threads around which keep 
the application from exiting.
On a side note: I'm also using the "deferToThread" method for some longer 
running tasks, so it might well be that it's one of those threads causing the 
issue. Is there a way to figure out which thread doesn't die? 
Any pointers are highly appreciated.



Open Source Solutions 4U, LLC	2570 Fleetwood Drive
Phone:  +1 650 872 2425		San Bruno, CA 94066
Cell:   +1 650 302 2405		United States
Fax:    +1 650 872 2417

More information about the Twisted-Python mailing list