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.

classification
Title: Implement lazy read for sockets
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: loewis, samtardieu
Priority: normal Keywords: patch

Created on 2003-12-04 10:57 by samtardieu, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch_lazy.txt samtardieu, 2003-12-04 10:57 Patch for Lib/socket.py implementing lazy read on sockets
Messages (3)
msg45018 - (view) Author: Samuel Tardieu (samtardieu) Date: 2003-12-04 10:57
When a socket is transformed into a file object using
the makefile() method, the resulting object read()
behaviour requires that read(N)
returns N characters or that the end of stream be reached.

This causes problems with XML parsers which call
read(BufferSize) to
get "something", not necessarily a full buffer.

The following patch adds a "lazy" attribute to each
socket._fileobject
instance, the default being set to False in order to be
backward
compatible. If this attribute is set to True, read(N)
will return at least
one character unless the end of stream is reached, and
no more than
N characters.
msg45019 - (view) Author: Samuel Tardieu (samtardieu) Date: 2003-12-04 11:47
Logged In: YES 
user_id=131394

Note: the original problem description came by Pierre
Palatin <pierre.palatin@enst.fr>.
msg45020 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-11-25 15:30
It seems there is very little interest in this patch; it also has a few problems:

- it does not include changes to the documentation and the test suite
- the feature can be implemented in a fairly easy way by inheriting from _fileobject;
   you just have to delegate read() nearly directly to recv.
- [IMO] "lazy" is a bad name for this feature; it has more to do with whether 
   it is blocking or not.
- I don't believe the patch can solve the original problem in all cases: it very much depends on how often the XML parser invokes .read()

For these reasons, I'm rejecting the patch.
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39663
2003-12-04 10:57:57samtardieucreate