[Twisted-Python] AlreadyCalledError trying more than a server

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Tue Sep 29 12:24:43 EDT 2009


On 08:27 am, antonio.beamud at gmail.com wrote:
>Hi all:
>I've implemented my client as comes in twisted documentation
>(FingerProxy example).
>I want to connect with several machines at the same time, send and
>receive data from this servers and start again (monitoring in one 
>word).
>
>I've created a ClientFactory and a loop like this:
>
>    conf['hosts'] = [list of hostnames]
>    commands = [list of string commands, like 'status' or 'temp']
>    def runall(data):
>        nodes = []
>
>        for h in conf['hosts']:
>                mcf = manager.ClientFactory(commands)
>                reactor.connectTCP(h, SERVER_PORT, mcf)
>                nodes.append(mcf.deferred)
>
>        dlist = defer.DeferredList(nodes)
>        dlist.addCallback(runall)
>        dlist.addErrback(lambda _: None)
>
>Only when the ClientFactory receives a 'bye' response, call's the
>d.callback('ok').
>With a only host, works perfect, but trying to run against two o more
>hosts, the next exception is raised:
>
>File "/usr/lib/python2.6/site-packages/twisted/internet/defer.py", line
>293, in _startRunCallbacks
>    raise AlreadyCalledError
>twisted.internet.defer.AlreadyCalledError:
>
>In my debug console:
>
>This is the deferredList
>[<Deferred at 0x84c3d6c>, <Deferred at 0x852d1ac>]
>...
>IPv4Address(TCP, 'ira', 10162) <Deferred at 0x84c3d6c>
>IPv4Address(TCP, 'lujuria', 10162) <Deferred at 0x84c3d6c  current
>result: 'ok'>
>
>Twisted is invoking the same deferred, and chaining them, the 'ok'
>result is produced by the 'ira' callback invokation instead using 
>everly
>deferred separately.
>
>What I'm doing wrong...?

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.

Jean-Paul



More information about the Twisted-Python mailing list