[Twisted-Python] Change in reactor.stop() in Twisted 8.x

Brian Granger ellisonbg.net at gmail.com
Wed May 7 14:41:16 EDT 2008


Hi,

We have been using Twisted for a long time and are migrating to 8.0.1.
 We are finding that code that ran fine with 2.5.0 is giving problems
with 8.0.1 and it appears to be related to what is happening in
reactor.stop().

The code that is failing looks like this:

##########

from twisted.internet import reactor

d = doSomeThingThatReturnsADeferred()
d.addCallback(handleOK)
d.addCallback(lambda _: reactor.stop())
reactor.run()

##########

The doSomeThingThatReturnsADeferred method is making XMLRPC calls
underneath the hood.

When we run this, it runs OK, but then blows up at the end with:

Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/internet/defer.py",
line 185, in addCallbacks
    self._runCallbacks()
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/internet/defer.py",
line 323, in _runCallbacks
    self.result = callback(self.result, *args, **kw)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/internet/base.py",
line 387, in _continueFiring
    callable(*args, **kwargs)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/internet/base.py",
line 524, in disconnectAll
    failure.Failure(main.CONNECTION_LOST))
--- <exception caught here> ---
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/python/log.py",
line 51, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/python/log.py",
line 36, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/python/context.py",
line 59, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/python/context.py",
line 37, in callWithContext
    return func(*args,**kw)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/internet/tcp.py",
line 577, in connectionLost
    self.connector.connectionLost(reason)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/internet/base.py",
line 937, in connectionLost
    self.factory.clientConnectionLost(self, reason)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/web/xmlrpc.py",
line 325, in clientConnectionLost
    self.deferred.errback(reason)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/internet/defer.py",
line 264, in errback
    self._startRunCallbacks(fail)
  File "/Library/Python/2.5/site-packages/Twisted-8.0.1-py2.5-macosx-10.5-i386.egg/twisted/internet/defer.py",
line 293, in _startRunCallbacks
    raise AlreadyCalledError
twisted.internet.defer.AlreadyCalledError:

I have checked and there is no failure object in my callback chain -
this is internal to Twisted.

Has the logic in reactor.stop changed recently?  Any ideas about what
would be causing this?

Thanks

Brian




More information about the Twisted-Python mailing list