[Python-Dev] SocketServer issues
Kristján Valur Jónsson
kristjan at ccpgames.com
Wed Mar 14 17:59:47 CET 2012
>I don't really think the ability to "create magic stackless mixin classes" should be a driving principle for the stdlib.
> I would suggest using a proper non-blocking framework such as Twisted.
There is a lot of code out there that uses SocketServer. It was originally designed to be easily extensable, with various mixins to control ultimate
Behavior. It just seems that there have been some design decisions made recently that make this subclassability / extensibility more difficult, and those
Are the two changes I pointed out. The thing with the select.select wouldn't be so bad if I could simply override serve_forever but that function
Can't be overridden because of the poor choice of adding __attributes to the class.
And, you would run into the same kind of trouble if you wanted to create a TwistedMixIn, a geventMixIn, or what not.
> In case you didn't notice, the built-in timeout support *also* uses select().
Yes, that's how the normal blocking framework supports timeout. Asynchronous frameworks do it differently, though.
> Then they should also replace the select module.
> Again, I don't think SocketServer (or any other stdlib module) should be designed in this regard.
And so we do too, but now every socket accept requires two rounds round the event loop. Also, emulating select() is not a critical part of frameworks designed to help you avoid to use it in the first place. The point of frameworks such as gevent, stackless, etc, is to let you write code with zillions of sockets without ever touching select. The quick and dirty emulated version I use, uses a thread to make it non-blocking!
It just seems odd to me that it was designed to use the "select" api to do timeouts, where timeouts are already part of the socket protocol and can be implemented more efficiently there.
Anyway, I'm not talking about rewriting anything, I merely want to fix some small design problems that prevent SocketServer to be specialized. I'll submit a simple patch for review.
From: python-dev-bounces+kristjan=ccpgames.com at python.org [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf Of Antoine Pitrou
Sent: 14. mars 2012 02:02
To: python-dev at python.org
Subject: Re: [Python-Dev] SocketServer issues
On Wed, 14 Mar 2012 04:26:16 +0000
Kristján Valur Jónsson <kristjan at ccpgames.com> wrote:
> Hi there.
> I want to mention some issues I've had with the socketserver module, and discuss if there's a way to make it nicer.
> So, for a long time we were able to create magic stackless mixin
> classes for it, like ThreadingMixIn, and assuming we had the
> appropriate socket replacement library, be able to use it nicely using tasklets.
I don't really think the ability to "create magic stackless mixin classes" should be a driving principle for the stdlib.
I would suggest using a proper non-blocking framework such as Twisted.
> So, my first question is: Why not simply rely on the already built-in
> timeout support in the socket module?
In case you didn't notice, the built-in timeout support *also* uses select().
Python-Dev mailing list
Python-Dev at python.org
More information about the Python-Dev