[Twisted-Python] Advise for heavy concurrency

Jean-Paul Calderone exarkun at divmod.com
Sat Dec 1 23:25:08 MST 2007


On Sat, 1 Dec 2007 19:40:28 -0800, Alec Matusis <matusis at yahoo.com> wrote:
>> > You cannot call any Twisted functions from a thread, with the
>> > exception
>>                                         ^^^^^^^^^^^^^ Er, I guess I
>> should have worded this more carefully. What I meant is: you cannot
>> call any Twisted functions from a different thread to the one the
>> reactor is running in, which includes any thread created with
>> deferToThread.
>>
>> > of callFromThread; so this would probably be pretty pointless.
>
>
>I am not sure I understood this: suppose my message sending loop simply
>loops over client protocol instances and calls
>transport.write(some_message)
>
>Why cannot I call this loop in a thread from the main reactor loop
>to have it non-blocking in case this sending loop is giant (over 1000s of clients)?

Because it is not a supported use of the API.  Twisted APIs, unless other-
wise documented, are not thread safe and can only be called from the thread
in which the reactor is running.

Jean-Paul




More information about the Twisted-Python mailing list