[Twisted-web] Having reactor run at the main thread make things harder for late adopters

Andrew Bennetts andrew-twisted at puzzling.org
Tue Nov 4 17:48:33 EST 2008

Tzury Bar Yochay wrote:
> I will first describe my application in a single sentence.
> Write a server that can serve TCP/UDP clients on several ports, and
> let the clients communicate with each other in a predefined protocol,
> while each can 'talk' to the server in a different protocol/port.
> In my case where I picked up Twisted relatively late in the project I
> need Twisted to plugged into my applocation and not the my application
> plugged-into Twisted (at least at this stage).
> Is there a way to by-pass this limitation?

You can run the reactor in any thread you like.  You probably need to pass
installSignalHandlers=False to reactor.run in a non-main thread, but otherwise
there's nothing stopping you running the reactor in a separate, non-main thread
if that's what's easiest for you.

> At this stage the main problem I see is having transport.write will
> have data transmitted immediately when called from another thread.

When calling into Twisted from non-Twisted threads, use reactor.callFromThread.
See <http://twistedmatrix.com/projects/core/documentation/howto/threading.html>.


More information about the Twisted-web mailing list