Shutting down twisted reacotr

Jp Calderone exarkun at divmod.com
Thu Apr 28 20:56:27 EDT 2005


On Thu, 28 Apr 2005 12:34:33 +0000 (UTC), Operation Latte Thunder <chris at angband.org> wrote:
>Jason  Mobarak <jason.mobarak at gmail.com> wrote:
>> Why do you want to do this in a thread? What's wrong with
>> reactor.callLater?
>>
>> import time
>> from twisted.internet import reactor
>>
>> def shutdown():
>>
>>    time.sleep(3)
>>    print "stopping"
>>    reactor.callFromThread(reactor.stop)
>>
>> reactor.callInThread(shutdown)
>> reactor.run()
>
>In the app I am playing with, I have a thread that reads from the console.
>When it terminates, I wanted it to shut down the reactor and couldn't use
>callLater.  However, callFromThread worked perfectly.   I guess I need to
>look at the docs some more to understand why its necessary

  In general, you cannot call Twisted APIs from a thread other than that in which the reactor is executing.  There are a few exceptions, callFromThread being one of them, but in general doing so has unpredictable behavior and is not supported.

  You also may be interested in twisted.internet.stdio and, in Twisted 2.0, twisted.conch.insults.

  Jp



More information about the Python-list mailing list