[Twisted-Python] <no subject>
John Santos
JOHN at egh.com
Mon Sep 19 07:19:07 MDT 2011
I'm a newbie compared to most of the people on this list, but this is a
question I think I can answer:
Your call to reactor.run() in main() won't return until the reactor shuts
down. After reactor.run(), *everything* happens in a deferred, until one
of them shuts down the reactor.
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.
If future events tell your application to make more connections, you
can perform more connectTCP()'s in the deferred triggered by the event.
------
def initialConnectionStartup:
for host in hosts:
host, port = (host, 23)
d = defer.Deferred()
factory = S12ClientFactory(d, username='root', password='admin')
Connection = reactor.connectTCP(host, port, factory, timeout=5)
d.addCallbacks(success, error)
d.addBoth(logout)
...
# __main__
reactor.callLater(0,initialConnectionStartup)
reactor.run()
------------
Hope this helps.
--
John Santos
Evans Griffiths & Hart, Inc.
781-861-0670 ext 539
More information about the Twisted-Python
mailing list