classification
Title: MS WINDOWS: input() swallows KeyboardInterrupt in Python 3.3
Type: behavior Stage: resolved
Components: Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Drekin, haypo, jcea, python-dev, sbt, tim.golden
Priority: normal Keywords: patch

Created on 2013-04-02 16:35 by Drekin, last changed 2013-04-03 14:05 by sbt. This issue is now closed.

Files
File name Uploaded Description Edit
input-ctrlc.patch sbt, 2013-04-03 10:42
Messages (13)
msg185845 - (view) Author: Adam Bartoš (Drekin) * Date: 2013-04-02 16:35
At least on Windows, input() doesn't raise KeyboardInterrupt when Ctrl-C is hit in Python 3.3 (it does in Python 3.2).

3.3:
>>> x = input() # Ctrl-C hit - no exception raised
>>> x
NameError

3.2:
>>> x = input() # Ctrl-C hit
KeyboardInterrupt
msg185873 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2013-04-03 01:26
Seems to be windows specific. It works fine on Linux and Solaris.
msg185877 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2013-04-03 01:46
It may be related to the following commit:

changeset:   77861:9523c122d6fc
user:        Tim Golden <mail@timgolden.me.uk>
date:        Fri Jun 29 18:39:26 2012 +0100
files:       Parser/myreadline.c
description:
Issue #1677: Handle better a race condition between the interactive interpreter and
the Ctrl-C signal handler on Windows
msg185878 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2013-04-03 01:47
@Drekin: What is your Windows version? How did you start Python?
msg185899 - (view) Author: Adam Bartoš (Drekin) * Date: 2013-04-03 08:49
I have Windows Vista Business SP2, 64-bit, (6.0.6002). If I start Python any way (from console, from shortcut, via py.exe or not) the same behavior occurs.
msg185900 - (view) Author: Adam Bartoš (Drekin) * Date: 2013-04-03 09:17
However it raises the exception correctly in IDLE.

The same behavior occured on Windows 7 Home Premium SP1, 64-bit, (6.1.7601).
msg185903 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2013-04-03 09:28
That's because IDLE uses a completely different input loop from the
console interpreter.

I'll try to get to this but I'm chock-a-block with other work at the
moment. If anyone else wants to dig, please do so. if the worst came to
the worst we could back out my previous changeset but that would still
leave us with an intermittent race-condition.
msg185906 - (view) Author: Adam Bartoš (Drekin) * Date: 2013-04-03 10:17
There is related weird behavior:

>>> try:
...     input()
... except KeyboardInterrupt:
...     print("exception occured")
...
# Ctrl-C hit
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
KeyboardInterrupt
>>>

Seems like handling of Ctrl-C is kind of “out of sync”.
msg185908 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2013-04-03 10:19
Maybe this is related to

    http://bugs.python.org/issue13673

which causes PyTraceback_Print() to fail if a signal is received but PyErr_CheckSignals() has not been called.

Note that wrapping in "try: ... except: raise" makes a traceback appear:

>>> try: input()
... except: raise
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyboardInterrupt
msg185912 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2013-04-03 10:42
Adding PyErr_CheckSignals() after PyOS_Readline() in builtin_input() seems to fix the problem.
msg185918 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2013-04-03 12:19
+1

Richard - are you in a position to commit / push?
msg185920 - (view) Author: Roundup Robot (python-dev) Date: 2013-04-03 12:51
New changeset 241cd716bf5f by Richard Oudkerk in branch '3.3':
Issue #17619: Make input() check for Ctrl-C correctly on Windows.
http://hg.python.org/cpython/rev/241cd716bf5f
msg185921 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2013-04-03 12:51
> Richard - are you in a position to commit / push?

Done.
History
Date User Action Args
2013-04-03 14:05:57sbtsetstatus: open -> closed
resolution: fixed
stage: resolved
2013-04-03 12:51:47sbtsetmessages: + msg185921
2013-04-03 12:51:01python-devsetnosy: + python-dev
messages: + msg185920
2013-04-03 12:19:11tim.goldensetmessages: + msg185918
2013-04-03 10:42:22sbtsetfiles: + input-ctrlc.patch
keywords: + patch
messages: + msg185912
2013-04-03 10:19:48sbtsetnosy: + sbt
messages: + msg185908
2013-04-03 10:17:39Drekinsetmessages: + msg185906
2013-04-03 09:28:08tim.goldensetmessages: + msg185903
2013-04-03 09:17:04Drekinsetmessages: + msg185900
2013-04-03 08:49:29Drekinsetmessages: + msg185899
2013-04-03 01:47:12hayposetmessages: + msg185878
2013-04-03 01:46:36hayposetnosy: + tim.golden, haypo
messages: + msg185877
2013-04-03 01:26:55jceasettitle: input() swallows KeyboardInterrupt in Python 3.3 -> MS WINDOWS: input() swallows KeyboardInterrupt in Python 3.3
2013-04-03 01:26:37jceasetnosy: + jcea
messages: + msg185873
2013-04-02 16:35:51Drekincreate