asynchat and threading

Anthony Baxter anthonybaxter at gmail.com
Wed Nov 24 20:39:35 EST 2004


On Wed, 24 Nov 2004 23:05:56 +0100, Martin v. Löwis <martin at v.loewis.de> wrote:
> AFAICT, the main complaint is that it is tied to the TCP transport,
> the sockets API, and the select/poll API. IOW, it cannot easily:
> - integrate TLS on top of TCP (because TLS might involve no-data
>    communications, e.g. when TLS negotation happens in the middle
>    of a TLS session),
> - integrate other transports, such as serial ports on Windows,
> - integrate other multi-endpoint wait APIs, such as IO completion
>    ports on Windows NT+, or kqueue on BSD.

- work with other event loops, such as GUI toolkits

There's also the problem that asyncore is more or less orphaned - there's
no-one on the python development team who supports it fully. Bugs in
it tend to get treated poorly. 

I wrote the original transport layer for pythondirector with asyncore. Under
any sort of load, it just starts to lose, bigtime. Random errors,
sockets getting
lost, and the like. Switching to twisted made it go much, much faster. Well,
to be fair, when I first ported to twisted, there was a nasty performance 
problem - this was relatively easy to track down and fix, and it's been fixed
for a long time now. Trying to fix asyncore was a nightmare.

The other thing to recommend twisted over asyncore is that twisted provides
a fuller set of tools for programming in an async manner, such as Deferreds.
With asyncore, you're kinda left on your own to do all this yourself.

twisted is too large to go into the python core as is - in addition, there's a 
mismatch between Python's release cycle speed and twisted's release
cycle speed (although the current delayed-until-who-knows-when Twisted
2.0 might be a harbinger of twisted slowing down to Python's speed <wink>)
It's possible that in the future a small core of twisted could end up in the
stdlib - this topic's come up a couple of times on the twisted list (most 
recently, a couple of months ago).

I wonder if the asyncore docs couldn't grow a 'See also' that points at twisted,
though...



More information about the Python-list mailing list