3

Run the following script:

import sys
sys.stdout.write(sys.stdin.read())

Then type:

a<ctrl-d><ctrl-d><ctrl-d>

In Python 2.6, 2.7, 3.3, 3.4, 3.5, the program will terminate after just 2 <ctrl-d>, but in Python 3.1 and 3.2, it takes 3.

Any clues as to why this is?

user48206
  • 77
  • 1
  • 2
  • 4
    It shouldn't even take 2. See [this bug report](http://bugs.python.org/issue1633941). The short answer is: because bugs, and those were fixed. – Martijn Pieters Nov 22 '16 at 22:26
  • Python 3 got a new I/O subsystem, and most bugs were ironed out by 3.3. So in 3.0-3.2 there may have been issues. I'm not going to dig up exactly which bug was fixed for this specific behaviour. – Martijn Pieters Nov 22 '16 at 22:28
  • @MartijnPieters one ^D (End of File) is normally enough, but with a pending input, the first ^D ends the input stream (and in IDLE Shell results in printing of 0 for 0 chars written) and the second kills the program. In Windows console, ^Z\n is required instead. – Terry Jan Reedy Nov 22 '16 at 22:38
  • @MartijnPieters Why shouldn't it take 2? According to POSIX, the first EOF flushes the pending input, the second EOF (with no pending input) causes read() to return 0 http://stackoverflow.com/a/21261742/4956890 – user48206 Nov 22 '16 at 22:40
  • @TerryJanReedy: right, I missed the the pending input there. – Martijn Pieters Nov 22 '16 at 22:42

0 Answers0