Repository navigation
IDLE restarts when one debugs code raising SystemExit #71136
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on May 4, 2016 To be more specific: if one runs a file, the shell is restarted (with the file name). In the file, raise SystemExit is normally the same as running off the end of the file, and a prompt is printed. If one runs a file with debugger on, [DEBUG ON] is printed before the prompt. However, SystemExit while debugging causes a Restart Shell before the [DEBUG ON] and >>> prompt. The 2nd restart does not normally happen when debugging finishes. It does not happen when any other exception is raised; instead a traceback is printed as normal.
This is a minor bug, but it does prevent interactive examination of the process after debugging.
There is special code in run.py to catch SystemExit and not print a traceback. My guess in a bug in RemoteDebugger.py that causes (allows) the execution process to exit or otherwise get detached from the IDLE process. When the IDLE process loses contact with the current execution process, it starts a new one.
Terry, Your
how to reproduceis more complicated than necessary. This bug can be reproduced by just turning on the debugger in a python shell and typingraise SystemExitthen pressing step in the debugger.Thanks, that may make debugging this (and creating a test) easier. I have only seriously used debugger with files, and often with breakpoints in the file.
This issue has worse consequences than I previously thought. It also affects
KeyboardInterruptwith worse consequences.If you run a program raising
KeyboardInterruptin the debugger, the shell will hang. Restarting the shell fixes this problem.bpo-14111 is about handling ^C while debugging. So for now I will assume that handling 'raise KeyboardInterrupt' is part of that issue.
The problem is cause by run.py:main function, when it catch KeyboardInterrupt or SystemExit, it won't put a blank msg back to response_queue, that cause the loop in run.py:main triggering except queue.Empty to continue the loop.
So, I think the KeyboardInterrupt hang is a bug, cause by the infinity loop above, but SystemExit will raise SystemExit again, and break down the loop, let the shell restart. I think this isn't a bug.
Let's say there is a code like this:
x = 10 print(x) raise SystemExit print(x)
When using IDLE to run this file without debugger, it will print 10 and leave below code. But when you type "x" in the shell, it will pop up 10, that means the shell environment didn't exit, still exist inside.
But if you open the debugger, let SystemExit break the loop and restart the shell, I think this is a normal behavior -- that it should exit the shell (and restart it)
PR 1711 fix KeyboardInterrupt with adding rpc.repsonse_queue.put, but it will not print out the exception traceback.
And for SystemExit, wait for discussion result.
Louie> If you run your example in Python with -i, you will see the same behavior, except for the traceback, as with IDLE.
F:\dev\cpython>python -i -c "x=10; print(x); raise SystemExit" Running Debug|Win32 interpreter... 10 Traceback (most recent call last): File "<string>", line 1, in <module> SystemExit >>> x 10
Ditto for "python -i testfile.py". I would like the behavior to be the same when debugging.
>> raise SystemExit does not normally cause a restart.
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directoryand removed3.9 (EOL)end of lifeend of life
on Nov 10, 2025 - removedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Jan 15, 2026 Both halves have the same cause: code run under the debugger bypasses
Executive.runcode(), so its exceptions escape to the request loop inrun.main(), which dropped aKeyboardInterruptwithout replying (hang) and re-raises aSystemExit(restart). #157566 fixes the hang; the restart can be done separately.'raise KeyboardInterrupt' in debugged code should be fixed. I changed the IDLE issues topic from Restart to Debugger. I hope someday to consider Debugger issues as a group and then include this minor issue of how 'raise SystemExit' in debugged code behaves.
- added a commit that references this issue
on Oct 9, 2026
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsIn Progress
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:
bugs.python.org fields:
Linked PRs