[Python-ideas] BufferedIO and detach

Antoine Pitrou solipsis at pitrou.net
Mon Mar 4 10:59:27 CET 2013

Le Mon, 4 Mar 2013 19:44:27 +1300,
Robert Collins
<robertc at robertcollins.net> a écrit :
> Yes exactly. A little more context on how I came to ask the question.
> I wanted to accumulate all input on an arbitrary stream within 5ms,
> without blocking for longer. Using raw IO + select, its possible to
> loop, reading one byte at a time. The io module doesn't have an API
> (that I could find) for putting an existing stream into non-blocking
> mode, so reading a larger amount and taking what is returned isn't
> viable.

What do you mean exactly by that?

> However, without raw I/O, select() will timeout because it consults
> the underlying file descriptor bypassing the buffer. So - the only
> reason to want raw I/O is to be able to use select reliably.

That's a pretty good reason actually. Raw I/O is exactly for those
cases. Non-blocking buffered I/O is a hard conceptual problem:

> An
> alternative would be being able to drain the buffer with no underlying
> I/O calls at all, then use select + read1, then rinse and repeat.

Have you tried peek()?



More information about the Python-ideas mailing list