[Twisted-web] finger tutorial: problems rewriting finger08.py to
use inlineCallbacks
Paul Goins
general at vultaire.net
Wed Dec 10 21:28:34 EST 2008
I'm having problems with using inlineCallbacks in the finger tutorial.
I've used them successfully in some other test programs, but in this case
I really don't know what I'm doing wrong.
Here's the FingerProtocol code from the finger tutorial:
class FingerProtocol(basic.LineReceiver):
def lineReceived(self, user):
self.factory.getUser(user) \
.addErrback(lambda _: "Internal error in server") \
.addCallback(lambda m:
(self.transport.write(m + "\r\n"),
self.transport.loseConnection()))
And here's my modified version:
class FingerProtocol(basic.LineReceiver):
@defer.inlineCallbacks
def lineReceived(self, user):
try:
data = yield self.factory.getUser(user)
except Exception:
data = "Internal error in server"
self.transport.write(data + "\r\n")
self.transport.loseConnection()
For some reason, in my version, the connection is getting terminated
before any writes can take place. Even if I comment out the
loseConnection line, still nothing goes across to the client and the
connection still gets terminated.
Could anyone tell me where I'm going wrong on this? Thanks in advance.
- Paul Goins
More information about the Twisted-web
mailing list