[Twisted-web] Reactor in a multithreaded program

Ellers ellers at ellerton.net
Mon May 23 00:20:05 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).

Ah - that makes sense, thanks :)

I tried that, but in itself it didn't solve my problem.

Would you expect the stop() message only to be picked up when the reactor
has some activity?

Is there an advised pattern for working with the reactor with multiple
threads?

Thanks :)
Ellers




More information about the Twisted-web mailing list