[Twisted-Python] Twisted-Python Digest, Vol 90, Issue 16

Fabian Rothfuchs fabian.rothfuchs at googlemail.com
Mon Sep 19 12:03:20 MDT 2011


>One thing you can do is make a small initial startup method that
>you supply to reactor.callLater with a delay of 0, that does the loop on
>the connectTCP()'s.  It will start up your initial set of connections.

Thanks John, this was *really* helpful!
I now did the following:
1. On Startup, the application starts one threaded reactor with a NOP
Protocol which
connects to 127.0.0.1:9 (discard socket).
2. The adapters use that threaded reactor as follows:
>>>for host in hosts:
>>> ...host, port = (host, 23)
>>> ...d = defer.Deferred()
>>> ...from twisted.internet import reactor
>>> ...factory = S12ClientFactory(d, username='root', password='admin')
>>> ...reactor.connectTCP(host, port, factory, timeout=5)
>>> ...d.addCallbacks(success, error)
>>> ...d.addBoth(logout)
>>> ...reactor.wakeUp()

The second important part was the wakeUp() call, which apparently triggers
the reactor
To end all blocking tasks.


My appreciations to Jeff and Johann as well for their help!

Fabian






More information about the Twisted-Python mailing list