Antoine Pitrou <pit...@free.fr> added the comment:

It is unlikely to be solvable at the Python level. Witness the raw stream's 
behaviour (in Python 3):

>>> sys.stdin.buffer.raw.read(1000)

If you type a letter followed by ^D (Linux) or ^Z (Windows), this returns 
immediately:

>>> sys.stdin.buffer.raw.read(1000)
x^Db'x'

But since the result is non-empty, the buffering layer will not detect the EOF 
and will call read() on the raw stream again (as the 1000 bytes are not 
satisfied). To signal EOF to the buffered stream, you have to type ^D or ^Z 
*without preceding it with another character*. Try the following:

>>> sys.stdin.buffer.read(1000)

You'll see that as long as you type a letter before ^D or ^Z, the read() will 
not return (until you type more than 1000 characters, that is):
- ^D alone: returns!
- a letter followed by ^D: doesn't return
- a letter followed by ^D followed by ^D: returns!
- a letter followed by ^D followed by a letter followed by ^D: doesn't return

This is all caused by the fact that a C read() on stdin doesn't return until 
either the end of line or EOF (or the requested bytes number is satisfied). 
Just experiment with:

>>> os.read(0, 1000)

That's why I say this is not solvable at the Python level (except perhaps with 
bizarre ioctl hackery).

----------
nosy: +pitrou

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15068>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to