[Twisted-Python] Stopping and restarting the reactor
Bob Ippolito
bob at redivi.com
Wed Jun 1 19:25:59 EDT 2005
On Jun 1, 2005, at 3:58 PM, Brian Granger wrote:
> I am using twisted's client capabilities in an interactive
> setting. To allow for interactive work, I have wrapped all my
> calls to connectTCP with a class that starts the reactor when a new
> set of connectTCP calls is made. I stop the reactor in the
> clientConnectionLost method of my ClientFactory (when there are no
> more connections).
>
> The first time I initiate a connectTCP call in my wrapper class
> everything works as expected: the reactor is started, twisted does
> its stuff, and the ClientFactory stops the reactor (giving me back
> interactive controll). BUT, if I the initiate another connectTCP
> call, the reactor starts, but then I get a User Timeout error
> showing up. That is, the second time, no connection is made. My
> ClientFactory again stops the reactor (this time in
> clientConnectionFailed), but then python hangs.
>
> My question: is the reactor designed to be started/stopped/
> restarted in a single session? If so, are there any considerations
> that I am missing? Why doesn't the connection get made the second
> time?
No, it's not. You should start the reactor at the beginning of your
app, and stop it when your app is going to quit. That's it.
threadedselectreactor <http://bob.pythonmac.org/archives/2005/04/17/
twisted-and-foreign-event-loops/> is probably more appropriate for
what you're trying to do.
-bob
More information about the Twisted-Python
mailing list