High performance IO on non-blocking sockets

Jeremy Hylton jeremy at zope.com
Fri Mar 14 17:36:37 CET 2003

On Fri, 2003-03-14 at 05:42, Troels Walsted Hansen wrote:
> I'm trying to do IO on non-blocking sockets (within the asyncore framework),
> and it seems to me that Python lacks a few primitives that would make this
> more efficient.

There's another source of inefficiency that has always bugged me about
the asyncore framework.  There are many layers of Python code between
the send() method you call on an aysncore socket and the send() call in
C.  A lot of these layers seem unnecessary.

There's a method on the socket like so:

    def send(self, data):
            result = self.socket.send(data)
            return result
        except socket.error, why:
            if why[0] == EWOULDBLOCK:
                return 0
                raise socket.error, why
            return 0

It seems like it would be much simpler to have a non-blocking socket
implemented in C that took a single argument and return a 2-tuple of
data and errno.  The C implemenation could use METH_O instead of
METH_VARARGS, and the caller wouldn't need to use a try/except.


More information about the Python-list mailing list