[Twisted-Python] AlreadyCalledError trying more than a server
andrew at bemusement.org
Wed Sep 30 10:10:16 EDT 2009
Antonio Beamud Montero wrote:
> exarkun at twistedmatrix.com escribió:
> > I don't think you've shared enough of your code for anyone to figure out
> > what you're doing wrong (aside from calling one Deferred's callback
> > method more than once). Your "runall" function above looks okay, so
> > perhaps the problem is in some other part of your code. An SSCCE
> > (<http://sscce.org/>) would be the best thing for you to share
> Yes, you're right. I've created an example with the minimal code to
> reproduce the problem.
This fails the “self-contained” criterion, by the way, as it assumes access to a
host called “romeo”.
[It also fairly clear isn't *completely* minimal either, e.g. I'm pretty sure
the addCallback(runall) is not required to see your problem. I also suspect
that you only need one connection to demonstrate this bug, but because it's not
self-contained it's hard to tell how far from minimal it actually is.]
Anyhow, my guess (it has to be a guess, as your example isn't self-contained, so
I cannot run it to examine the problem for myself), is that the problem is that:
a) you create one Deferred per connection (self.deferred in MyClientFactory),
b) your lineReceived invokes gotData which often calls that deferred without
any robust defence against calling that deferred multiple times.
e.g. consider a server that sends "221 2.0.0 Bye" followed by a blank line.
The specific data triggering your problem should be obvious from the output of
your “print repr(data)” line in gotData.
More information about the Twisted-Python