Actually, there are two questions. However, I think they are closely related, so I ask them together. I use Python 2.7.10 32bit under Windows.
The first one is about this program:
import sys
sys.stdin.readline()
a = 1
b = 2
print 'hello'
When the program asks for input, if I press Ctrl-C, the program will be stopped by KeyboardInterrupt. However, this exception will happen in print 'hello'
, not in sys.stdin.readline()
.
The second one is about this program:
import sys
while True:
sys.stdin.readline()
When I want to stop this program, I have to first press Ctrl-C, then press Enter or press Ctrl-C again.
Neither of the problems happens under Linux, and they are annoying when debugging. I will be grateful if someone can give an detailed explanation.