[issue12053] Add prefetch() for Buffered IO (experiment)

Martin Panter report at bugs.python.org
Wed Apr 8 05:34:20 CEST 2015


Martin Panter added the comment:

Sounds like this might be more appropriate for the BufferedReader and related classes, and less so for the writer and abstract base class.

The proposed API seems strange to me. Is there an illustration of how it might be used? I suspect it wouldn’t be all that useful, and could more or less be implemented with the existing methods:

def prefetch(buffered_reader, buffer, skip, minread):
    buffered_reader.read(skip)
    consumed = buffered_reader.readinto(buffer[:minread])
    if consumed < minread:
        return consumed
    spare = len(buffer) - consumed
    extra = buffered_reader.peek(spare)[:spare]
    total = consumed + len(extra)
    buffer[consumed:total] = extra
    return total

Maybe it would be better to focus on clarifying or redefining the existing peek() method (Issue 5811), rather than making a brand new do-everything method which only seems to do what the other methods already do.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12053>
_______________________________________


More information about the Python-bugs-list mailing list