[Twisted-Python] Tie two event loops

Paul Wilson paulalexwilson at gmail.com
Wed Jul 2 10:46:05 EDT 2008

Hi all,

I'm new to twisted but am having trouble getting my head around how to
structure my application with this new approach.

I'm creating a server that accepts client connections and then drives
the client according to a simple, line-oriented protocol. The server
sends the request (1 line), and receives a single lined result. I'd
like the server to offer an API to generate the correct request lines
to the client, and return the results (either blocking or
asynchronously). So in effect, I have two event loops, one from the
Network and one from whatever's sending the API requests (command

Can anyone offer any guidance on how to tie these two parts together?
My instinct is to have the two event loops in separate threads and
communicate through Queue.Queue, but that doesn't seem to follow the
spirit of twisted. And I guess I'd have to somehow tell the reactor to
poll the Queue object for requests, and then dispatch it to the
relevant method to send out to the client. I've looked at
threadedselectreactor but can't seem to find any decent documentation
to even decide if it's write for what I want.

Any advice would be much appreciated.


More information about the Twisted-Python mailing list