This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients amaury.forgeotdarc, benjamin.peterson, giampaolo.rodola, pitrou, stutzbach
Date 2010-09-14.23:58:48
SpamBayes Score 1.11022e-16
Marked as misclassified No
Message-id <>
Le mardi 14 septembre 2010 à 23:19 +0000, Giampaolo Rodola' a écrit :
> 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.

If it wasn't supposed to, we can add that support.
The statement comes from the 2.x doc; 2.x didn't have a notion of non-blocking file-like objects at all, so it makes sense.

> IMO, I think it's a matter of figuring out whether makefile() should 
> provide a socket-like behavior or a file like-behavior first.

Well, since it claims to implement RawIOBase, it should provide a RawIOBase-like behaviour :)
(and, in any case, the only use of makefile() is to return something file-like. If you want socket-like behaviour, just use the socket)

Returning None is what raw I/O objects are supposed to do when they fail reading or writing even a single byte. It is designed and documented as such.

(the readinto() doc you mentioned lacked that precision, but I've just fixed it)

The reason None is returned (rather than 0 or b'') is so that the caller can recognize the situation and take appropriate measures.
For example, if read() returns None, it means some bytes *may* be following but we'll have to wait (select/poll/...) first; if read() returns 0, conversely, it means we've reached EOF (or, on a socket, that the peer has shutdown its side of the connection). These are two very different situations.

["file-like behaviour"]
> otherwise they should be
> silenced/handled internally or makefile() just fail immediately as
> there's not such thing as "non-blocking files".

Non-blocking files exist:

>>> import fcntl, os, io
>>> r, w = os.pipe()
>>> fcntl.fcntl(r, fcntl.F_SETFL, os.O_NONBLOCK)
>>>, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 11] Resource temporarily unavailable

(It seems that on regular files O_NONBLOCK may not have an effect; not under Linux anyway)
Date User Action Args
2010-09-14 23:58:51pitrousetrecipients: + pitrou, amaury.forgeotdarc, giampaolo.rodola, benjamin.peterson, stutzbach
2010-09-14 23:58:51pitrousetmessageid: <>
2010-09-14 23:58:49pitroulinkissue9854 messages
2010-09-14 23:58:48pitroucreate