[Twisted-web] Reactor in a multithreaded program

Andrew Bennetts andrew-twisted at puzzling.org
Sun May 22 17:24:32 MDT 2005

On Sun, May 22, 2005 at 03:12:13PM -0700, Ellers wrote:
> Hi all
> What is the right way to use a reactor in a multithreaded program?
> The program I'm writing is a command line program that needs to use the
> readline package. Readline blocks so I need to put the reactor (or the
> readline call) in a separate thread.
> I can start the reactor ok if I set installSignalHandlers=0. But calling
> reactor.stop() from the main thread doesn't seem to stop it.

Nothing in Twisted is thread-safe, except for reactor.callFromThread.  So,
if you want to stop the reactor from thread aside from the one the reactor
is in, you need to do reactor.callFromThread(reactor.stop).


More information about the Twisted-web mailing list