[Twisted-Python] AlreadyCalledError trying more than a server

Antonio Beamud Montero antonio.beamud at gmail.com
Tue Sep 29 04:27:34 EDT 2009

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)

        dlist = defer.DeferredList(nodes)
        dlist.addErrback(lambda _: None)

Only when the ClientFactory receives a 'bye' response, call's the
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

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...?

A lot of thanks.

More information about the Twisted-Python mailing list