[Twisted-Python] using a reactor in a loop

Tom Brown brown at esteem.com
Thu Mar 1 13:46:10 EST 2007

On Thursday 01 March 2007 09:42, L. Daniel Burr wrote:
> Hi Tom,
> On Thu, 01 Mar 2007 11:21:50 -0600, Tom Brown <brown at esteem.com> wrote:
> > Hello,
> >
> > I am trying to use a reactor in a loop. The application will go through
> > the
> > loop twice then hang when trying to stop the protocol. Here's my loop:
> The reactor provides an event loop already, so I am confused as to why
> you are trying to run it inside another loop.  Based on the code you
> have posted here, I can't ascertain what your goal is.
> Generally speaking, you'd be better served by using the reactor's
> loop instead of your own, and stopping/starting your listeners,
> rather than the reactor itself.
> Also, stopping the reactor from within a protocol is probably
> not ideal.  That's sort of like telling your OS to shut down
> when you're done saving a file ;)

Thanks for your reply.

My goal is this:
1) do specific tasks
2) run the server and wait for a connection
3) when a connection is made, do tasks as instructed by the client in the 
AqapProtocol code.
4) when connection is lost, close server and go back to 1)

Shutting down the server is not necessary if I could get past the 
reactor.run(). A previous post suggested I use deferreds. So, that is 
probably what I need to. I just need to learn how to use them.


More information about the Twisted-Python mailing list