[Twisted-Python] If lineReceived returns deferred, then connection is dropped and this deferred given as error message
Marcin Kasperski
Marcin.Kasperski at softax.com.pl
Tue Oct 31 08:52:37 MST 2006
I am observing the twisted behaviour which seems rather strange to me.
In short: if lineReceived returns some deferred, then the whole connection is
aborted, moreover, this deferred is returned as error message.
Longer story (the code pieces extracted from quite large app, I have not
yet tried writing small example)
### Crucial code fragments
class SomeProtocol(basic.LineReceiver):
(...)
def lineReceived(self, line):
(...)
return defer.succeed(997) # magic value I can recognize easily
class SomeFactory(protocol.ReconnectingClientFactory):
(...)
def clientConnectionLost(self, connector, reason):
logger.warn("Connection lost. Reason: %s\nTraceback: %s" % (
reason.getErrorMessage(), reason.getTraceback()))
protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
reactor.connectTCP(HOST, PORT, SomeFactory(...))
reactor.run()
### Things seen in log file
myapp : WARNING Connection lost. Reason: <Deferred at 0xB551E1ECL current result: 997>
Traceback: Traceback (most recent call last):
Failure: <type 'instance'>: <Deferred at 0xB551E1ECL current result: 997>
(you recognized this 997, didn't you?)
### Extra info
1. Removing return defer.succeed() from lineReceived helps.
2. I wanted to return deferreds from lineReceived because I wanted to write unit tests
testing my factory object (and in some cases to check whether all worked correctly
required waiting for some spawned deferred calls).
More information about the Twisted-Python
mailing list