[Twisted-Python] <no subject>

Jeffrey Ollie jeff at ocjtech.us
Mon Sep 19 07:02:26 MDT 2011


On Mon, Sep 19, 2011 at 7:44 AM, Fabian Rothfuchs
<fabian.rothfuchs at googlemail.com> wrote:
>
> for host in hosts:
>     host, port = (host, 23)
>     d = defer.Deferred()
>     from twisted.internet import reactor
>     factory = S12ClientFactory(d, username='root', password='admin')
>     Connection = reactor.connectTCP(host, port, factory, timeout=5)
>     d.addCallbacks(success, error)
>     d.addBoth(logout)
> reactor.run()

I'd put "from twisted.internet import reactor" outside of the loop.

> So I wonder, if you can dynamically feed the reactor with new tasks (I use
> connectTCP for it), as it's not possible to start/stop it on demand (or if
> there's an alternative approach):

Yes, you can, you should be able to call connectTCP any time before
the reactor is shut down with reactor.stop().

> from twisted.internet import reactor
>
> reactor.run()
> 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)
>
> If I try to do so, connection.state never leaves 'connecting' and I cannot
> see any traffic going through the wire on the TCPDump?
> I'd really appreciate any hints, as I'm feeling a bit lost :-)

The first thing I saw is that you'll want "reactor.run()" after the
loop, otherwise that code won't get run until the system is ready to
shut down.

-- 
Jeff Ollie




More information about the Twisted-Python mailing list