Skip to content

IDLE restarts when one debugs code raising SystemExit #71136

Description

@pppery
mannequin
BPO 26949
Nosy @terryjreedy, @pppery, @mlouielu
PRs
  • gh-71136: IDLE: Fix hanging when raise KeyboardInterrupt with debugger open #1711
  • 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 2016-05-04.12:49:03.499>
    labels = ['expert-IDLE', 'type-bug', '3.9']
    title = 'IDLE restarts when one debugs code raising SystemExit'
    updated_at = <Date 2019-09-20.20:57:18.028>
    user = 'https://github.com/pppery'

    bugs.python.org fields:

    activity = <Date 2019-09-20.20:57:18.028>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['IDLE']
    creation = <Date 2016-05-04.12:49:03.499>
    creator = 'ppperry'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 26949
    keywords = []
    message_count = 9.0
    messages = ['264861', '264863', '264867', '265097', '265101', '294124', '294125', '294775', '352889']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'ppperry', 'louielu']
    pr_nums = ['1711']
    priority = 'normal'
    resolution = None
    stage = 'test needed'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26949'
    versions = ['Python 3.9']

    Linked PRs

    Activity

    1. terryjreedy commented on May 4, 2016

      @terryjreedy
      Member

      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.

    2. pppery commented on May 4, 2016

      ppperymannequin
      MannequinAuthor

      Terry, Your how to reproduce is more complicated than necessary. This bug can be reproduced by just turning on the debugger in a python shell and typing raise SystemExit then pressing step in the debugger.

    3. terryjreedy commented on May 5, 2016

      @terryjreedy
      Member

      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.

    4. pppery commented on May 7, 2016

      ppperymannequin
      MannequinAuthor

      This issue has worse consequences than I previously thought. It also affects KeyboardInterrupt with worse consequences.

      If you run a program raising KeyboardInterrupt in the debugger, the shell will hang. Restarting the shell fixes this problem.

    5. terryjreedy commented on May 7, 2016

      @terryjreedy
      Member

      bpo-14111 is about handling ^C while debugging. So for now I will assume that handling 'raise KeyboardInterrupt' is part of that issue.

    6. mlouielu commented on May 22, 2017

      mlouielumannequin
      Mannequin

      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)

    7. mlouielu commented on May 22, 2017

      mlouielumannequin
      Mannequin

      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.

    8. terryjreedy commented on May 30, 2017

      @terryjreedy
      Member

      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.

    9. terryjreedy commented on Sep 20, 2019

      @terryjreedy
      Member

      >> raise SystemExit does not normally cause a restart.

    10. transferred this issue fromon Apr 10, 2022
    11. moved this to In Progress in IDLE Issueson Jul 27, 2022
    12. added
      stdlibStandard Library Python modules in the Lib/ directory
      and removed on Nov 10, 2025
    13. removed
      stdlibStandard Library Python modules in the Lib/ directory
      on Jan 15, 2026
    14. serhiy-storchaka commented on Sep 15, 2026

      @serhiy-storchaka
      Member

      Both halves have the same cause: code run under the debugger bypasses Executive.runcode(), so its exceptions escape to the request loop in run.main(), which dropped a KeyboardInterrupt without replying (hang) and re-raises a SystemExit (restart). #157566 fixes the hang; the restart can be done separately.

    15. added 3 commits that reference this issue on Sep 26, 2026
    16. terryjreedy commented on Sep 26, 2026

      @terryjreedy
      Member

      '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.

    17. added a commit that references this issue on Oct 9, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      topic-IDLEtype-bugAn unexpected behavior, bug, or error

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions