Fw: [Twisted-Python] Different behavior under Windows and Linux

Itamar Shtull-Trauring itamar at itamarst.org
Wed Jan 2 09:06:54 EST 2008

On Wed, 2008-01-02 at 15:18 +0300, W K wrote:
>         thread.start_new_thread(self.send, ())
>         reactor.connectTCP(self.host, self.port, self)

You can't call Twisted APIs from threads. This will fail in a variety of
fun ways, as you can see.

Either use reactor.callFromThread(self.connector.sendMessage, data), or
use deferToThread to run your non-Twisted computation in a thread and
then addCallback your Twisted calls. Or, best of all, don't use threads
at all: they're almost always unnecessary when using Twisted. You
probably want to use twisted.internet.task.LoopingCall to do what you're
currently doing.

More information about the Twisted-Python mailing list