[New-bugs-announce] [issue9854] SocketIO should return None on EWOULDBLOCK

Antoine Pitrou report at bugs.python.org
Tue Sep 14 18:20:11 CEST 2010

New submission from Antoine Pitrou <pitrou at free.fr>:

SocketIO claims to implement RawIOBase, but it lets blocking IO errors pass through on non-blocking sockets:

>>> s = socket.create_connection(("python.org", 80)); s.settimeout(0.0)
>>> f = s.makefile("rb", buffering=0)
>>> f.readinto(bytearray(10))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/antoine/py3k/nntp-9360/Lib/socket.py", line 228, in readinto
    return self._sock.recv_into(b)
socket.error: [Errno 11] Resource temporarily unavailable

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

There also seems to be a problem in the default read() implementation in RawIOBase, which doesn't accept a possible None result from readinto():

>>> f.readinto = lambda x: None
>>> f.read(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object cannot be interpreted as an integer

(the RawIOBase docs themselves don't mention that readinto() can return None, but it's the only logical possibility: catching EWOULDBLOCK in read() but not in readinto() wouldn't make sense)

components: IO, Library (Lib)
messages: 116408
nosy: amaury.forgeotdarc, benjamin.peterson, pitrou, stutzbach
priority: normal
severity: normal
status: open
title: SocketIO should return None on EWOULDBLOCK
type: behavior
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list