sys.stdin does not close on ctrl-d
问题 I have the following code in program.py: from sys import stdin for line in stdin: print line I run, enter lines, and then press Ctrl + D , but the program does not exit. This does work: $ printf "echo" | python program.py Why does the program not exit when I press Ctrl + d ? I am using the Fedora 18 terminal. 回答1: Ctrl + D has a strange effect. It doesn't close the input stream, but only causes a C-level fread() to return an empty result. For regular files such a result means that the file is