[Twisted-Python] Twisted-Python Digest, Vol 90, Issue 16

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Mon Sep 19 15:53:58 EDT 2011

On 07:02 pm, fabian.rothfuchs at googlemail.com wrote:
>Well no, not from multiple threads.
>I have only two threads ­ one main thread, which is the Django 
>and one detached
>thread for the reactor, as the reactor itself would be blocking Django.
>All Adapters are in Django, and are reaching out to the one reactor in 
>thread without threading themselves.
>Is this 'allowed' ?

No.  You can only call Twisted APIs in a single thread.  The thread 
everything will happen in is the one you call reactor.run() in, so 
that's the one you have to call all other APIs in.  There is one 
exception, reactor.callFromThread, which you can call from any thread. 
It lets you schedule another call to happen in the same thread as 
reactor.run was called in.


More information about the Twisted-Python mailing list