<div dir="ltr"><div>Hi Chris,<br><br><br></div>It will probably not surprise you that I like Twisted :-)<br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 12, 2014 at 8:28 AM, Chris Withers <span dir="ltr"><<a href="mailto:chris@simplistix.co.uk" target="_blank">chris@simplistix.co.uk</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
So, I see python now has a plethora of async frameworks and I need to try and pick one to use from:<br>
<br>
- asyncio/tulip<br>
- tornado<br>
- twisted<br></blockquote><div><br></div><div>Twisted has a thing called Cyclone, which I hear (but that's only hearsay) gives you Tornado's API on top of twisted, so you get all of the stuff below for free.<br></div>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
>From my side, I'm looking to experimentally build a network testing tool that will need to speak a fair few protocols, both classic tcp and multicast-based, and have a web api living on top of it that most likely will have a websocket for pumping data to the browser. It'll also need to write out JUnit-compatible xml results, but that's like the easiest bit ;-)<br>

</blockquote><div><br></div><div>I don't know which protocols you are interested in specifically; later on in the e-mail you mention that it's *probably* not already extant. Twisted comes with a huge number of protocols already implemented. It has TCP support (duh) as well as an interface for UDP multicast.<br>

<br>Twisted has a third party project called txsockjs which works excellently, both by itself and in the context of other (HTTP) resources. sockjs is a protocol which is basically "websockets, damnit", even when the consumer is a bad browser like IE6.<br>

</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I'd like to be able to serve the rest of the web api using a pyramid wsgi app if possible, and I'd like to be able to write the things that process requests in and validation out in a synchronous fashion, most likely spinning off a thread for each one.<br>

</blockquote><div><br></div><div>Twisted comes with a threadpool-backed WSGI server. (When I say threadpool-backed I mean that the WSGI requests are handled in threads; the IO itself of course comes from the Twisted reactor).<br>

</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

The protocols are all financial (do we really not have a pure-python FIX library?!) but none are likely to have existing python implementations.<br></blockquote><div><br></div><div>I find twisted to be a great tool for writing protocol implementations. I have written tools for querying all sorts of gnarly proprietary protocols over all sorts of gnarly transports (packet radio; it's totally a thing), and more recently for doing crazy things like multiplexing stream transports over existing RPC protocols. (Like, you see a local port come up, and that actually creates a virtual stream connection over an existing RPC thing to some virtual server on the other end of the wire: <a href="https://www.youtube.com/watch?v=W_jEIvugwes">https://www.youtube.com/watch?v=W_jEIvugwes</a>).<br>

<br></div><div>Twisted has had so many people write so many protocols in it that also the testing tools (MemoryReactor, StringTransport) are great. Especially if you are writing something very close to a wire protocol you will undoubtedly enjoy those amenities. There's also tons of composable things for receiving delimited lines, nestrings, etc. It's hard to tell what you will be looking for since I don't know details about your protocol, but having written more than a few protocol implementations I'm going to wager a guess and say Twisted has it or a third party thing for twisted has it.<br>

</div><div><br></div><div>Even though I mostly write Clojure now, I still write my networking stuff in Twisted. Macros are cool. Eleven years worth of battle-tested code is better.<br></div><div><br></div><div>That said, tulip is nice in that you can also write protocol implementations that will look similar :-)<br>

</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
How should I pick between the options? What would people recommend and why?<br></blockquote><div><br></div><div>Twisted, emphatically and without reservation, for all the above reasons. It's stable. All the stuff you need has been tried and tested extensively in production. It runs on PyPy, and usually a damn sight faster than on CPython, too.<br>

</div><div><br></div><div>A common criticism of Twisted is that it "takes over" your codebase. I am speaking at PyCon in about a month to demonstrate that that isn't true. (It just looks that way, because once people use it, they don't want to go back... ;-))<br>

</div><div><br></div><div>hth<br>lvh<br></div></div></div></div>