[issue9854] SocketIO should return None on EWOULDBLOCK

Giampaolo Rodola' report at bugs.python.org
Wed Sep 15 01:19:19 CEST 2010

Giampaolo Rodola' <g.rodola at gmail.com> added the comment:

I've never used socket.socket.makefile so I'm not sure, but its documentation says:

> The socket must be in blocking mode (it can not have a timeout).

If the statement is there because EAGAIN/EWOULDBLOCK were originally raised then it should be removed, otherwise I question whether makefile() is actually supposed to support non-blocking sockets in the first place.
IMO, I think it's a matter of figuring out whether makefile() should provide a socket-like behavior or a file like-behavior first.
In the first case I would expect all errors be raised as if I'm dealing with a common socket, otherwise they should be silenced/handled internally or makefile() just fail immediately as there's not such thing as "non-blocking files".

> Instead, readinto() should detect the blocking condition (EAGAIN / EWOULDBLOCK) and 
> return None (same for write(), I imagine).

io.RawIOBase.readinto doc says: 

> Read up to len(b) bytes into bytearray b and return the number of bytes read.

...so returning 0 instead of None looks more natural to me.
Same for write, also because:

>>> open('xxx', 'w').write('')

I've also noticed that socket.SocketIO.readinto has a while loop which continues in case of EINTR and that's something which should be removed in case makefile() actually intends to support non-blocking sockets.


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list