Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyboardInterrupt handling and traceback broken on Windows 10 #69563

Open
mdf mannequin opened this issue Oct 11, 2015 · 5 comments
Open

KeyboardInterrupt handling and traceback broken on Windows 10 #69563

mdf mannequin opened this issue Oct 11, 2015 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-windows type-bug An unexpected behavior, bug, or error

Comments

@mdf
Copy link
Mannequin

mdf mannequin commented Oct 11, 2015

BPO 25376
Nosy @pfmoore, @tjguk, @bitdancer, @vadmium, @zware, @zooba

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2015-10-11.12:32:24.874>
labels = ['interpreter-core', 'type-bug', 'OS-windows']
title = 'KeyboardInterrupt handling and traceback broken on Windows 10'
updated_at = <Date 2015-10-13.04:40:06.506>
user = 'https://bugs.python.org/mdf'

bugs.python.org fields:

activity = <Date 2015-10-13.04:40:06.506>
actor = 'martin.panter'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core', 'Windows']
creation = <Date 2015-10-11.12:32:24.874>
creator = 'mdf'
dependencies = []
files = []
hgrepos = []
issue_num = 25376
keywords = []
message_count = 5.0
messages = ['252800', '252801', '252805', '252816', '252912']
nosy_count = 7.0
nosy_names = ['paul.moore', 'tim.golden', 'r.david.murray', 'martin.panter', 'zach.ware', 'steve.dower', 'mdf']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue25376'
versions = ['Python 3.4', 'Python 3.5']

@mdf
Copy link
Mannequin Author

mdf mannequin commented Oct 11, 2015

Pressing Ctrl+C to raise a KeyboardInterrupt while waiting for user input in an input() call yields an incomplete traceback.

The behaviour appears in a Python REPL session started by issuing "python" without quotes in a Windows cmd session:

Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> input("Question: ")
Question: Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
>>>

When executing input_test.py (a single line Python source code file containing just an input("Question: ") call) from the cmd prompt by issuing "python input_test.py" without quotes, every other time the traceback is incomplete and every other time the Ctrl+C keypress yields, erroneously, an EOFError instead of a KeyboardInterrupt:

C:\x>python input_test.py
Question: Traceback (most recent call last):
  File "input_test.py", line 1, in <module>
    input("Question: ")
EOFError
^C
C:\x>python input_test.py
Question: Traceback (most recent call last):
  File "input_test.py", line 1, in <module>

C:\x>

@mdf mdf mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-windows type-bug An unexpected behavior, bug, or error labels Oct 11, 2015
@mdf
Copy link
Mannequin Author

mdf mannequin commented Oct 11, 2015

Just tried the same in an IDLE session, but it seems to display the KeyboardInterrupt correctly:

Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> input("Question: ")
Question: 
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    input("Question: ")
  File "C:\y\Python\Python35\lib\idlelib\PyShell.py", line 1385, in readline
    line = self._line_buffer or self.shell.readline()
KeyboardInterrupt
>>> 

Running the file input_test.py I meantioned in my original report doesn't seem to diplay anything when Ctrl+C is pressed:

============= RESTART: C:\x\input_test.py =============
Question:

>>

@mdf
Copy link
Mannequin Author

mdf mannequin commented Oct 11, 2015

Did some more testing. KeyboardInterrupt traceback displays properly when pressing Ctrl+C during an infinite loop:

Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> while True:
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
KeyboardInterrupt
>>>

Also when running a file in a similar way as I did in the original bug report:

C:\x>python infinite_loop.py
Traceback (most recent call last):
  File "infinite_loop.py", line 2, in <module>
    pass
KeyboardInterrupt

C:\x>

Could this mean that the problem is more related to reading stdin than the actual KeyboardInterrupt?

@bitdancer
Copy link
Member

Yes, this is probably a duplicate of bpo-18597.

@vadmium
Copy link
Member

vadmium commented Oct 13, 2015

I am no Windows expert, but I read in bpo-18597 that Ctrl+C is treated as EOF, except that a SIGINT is also sent in the background. This would explain why you see an EOFError. The partial traceback may also be from the same EOFError. Or both cases could be truncated reports of KeyboardInterrupt chained onto EOFError.

I understand the code path for input() may bypass the usual stdin.read() and readline() methods. bpo-18597 is about readline(), so it may not be an exact duplicate.

See also bpo-17619, which hints that KeyboardInterrupt handling for input() was worked on and fixed in 3.3. So why is it broken again in 3.4? A regression test would be nice, if at all possible. Does Windows have an equivalent of pseudo terminals?

Possibly also related is bpo-13673, about functions (like input) raising an exception (like EOFError), when SIGINT has been received. It mentions the interpreter completely failing to report the entire traceback, or truncating the traceback. It might be worth trying out the patch there. It might also be interesting to check sys.last_value in the interactive case.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants