[Twisted-Python] thread in reactor problem
radix at twistedmatrix.com
Wed Aug 8 00:22:10 EDT 2007
On 8/7/07, Yan Zhu <nayuhz at gmail.com> wrote:
> Hi all, I run a reactor in my thread, so I will get many connection by
> twisted, and I run another thread for write back data to any connection.
You don't need to have multiple threads to communicate with multiple
> But I've found the data is in buffer, not sent back
This is because you're calling Twisted functions from non-reactor
threads. Twisted doesn't support this. The *only* threadsafe function
to call is reactor.callFromThread. You pass it a function to run in
the reactor thread.
If all you need is concurrent asynchronous I/O, you don't need
threads. Twisted is an *asynchronous* networking framework. You can do
all of your communication efficiently in one thread.
International Man of Twistery
More information about the Twisted-Python