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 docs@python, jaraco, pitrou, r.david.murray, serhiy.storchaka, zach.ware
Date 2012-06-14.20:18:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1339705098.34.0.171649011196.issue15068@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2012-06-14 20:18:18pitrousetrecipients: + pitrou, jaraco, r.david.murray, docs@python, zach.ware, serhiy.storchaka
2012-06-14 20:18:18pitrousetmessageid: <1339705098.34.0.171649011196.issue15068@psf.upfronthosting.co.za>
2012-06-14 20:18:17pitroulinkissue15068 messages
2012-06-14 20:18:17pitroucreate