More generally, the issue happens with all exceptions raised by other threads.
Run the code below and interrupt with ctrl+c.
# If part of a file, potentially more code before the loop. Traceback says -1 regardless.
for i in range(30000000):
if not i%1000000:
pass # Or any other operation here that is faster than iterating a million i values.
With the following traceback:
Traceback (most recent call last):
File "/home/panta/issue.py", line -1, in <module>
KeyboardInterrupt
The issue disappears as soon as we add just a bit more to the loop
for i in range(30000000):
if not i%1000000: # The 3.10 traceback points to this line.
pass
pass # The 3.11 and 3.12 tracebacks point to this line.
Traceback (most recent call last):
File "/home/panta/issue.py", line 4, in <module>
pass
KeyboardInterrupt
The issue persists whether running from the shell or as a file or even using exec. It works the same inside functions/methods. It exists in 3.11 and 3.12 but not 3.10, across Windows and Linux.
- CPython versions tested on: 3.10.6 (no issue), 3.11.1 (issue), 3.11.4 (issue), 3.12.0rc1 (issue)
- Operating system and architecture: Windows 10 and Ubuntu 22.04.2 LTS (WSL)
Linked PRs
More generally, the issue happens with all exceptions raised by other threads.
Run the code below and interrupt with ctrl+c.
With the following traceback:
The issue disappears as soon as we add just a bit more to the loop
The issue persists whether running from the shell or as a file or even using
exec. It works the same inside functions/methods. It exists in 3.11 and 3.12 but not 3.10, across Windows and Linux.Linked PRs