From 717c3b72e84618a5ec1b59f5b68a92935ba004ec Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 15 Sep 2026 18:46:43 +0300 Subject: [PATCH] gh-71136: Fix IDLE Shell hang after KeyboardInterrupt under the debugger Code run under the debugger bypasses Executive.runcode(), so the KeyboardInterrupt reached the request loop in run.main(), which did not reply to the request. Report it and reply, but only if a request was being executed. Co-authored-by: Louie Lu Co-Authored-By: Claude Opus 5 (1M context) --- Lib/idlelib/run.py | 7 ++++++- .../IDLE/2026-09-15-15-46-35.gh-issue-71136.vwGO0v.rst | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/IDLE/2026-09-15-15-46-35.gh-issue-71136.vwGO0v.rst diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 2725043b4ed9253..f463e29e2d4f5c8 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -163,6 +163,7 @@ def main(del_exitfunc=False): ).start() while True: + request = None try: if exit_now: try: @@ -173,9 +174,9 @@ def main(del_exitfunc=False): try: request = rpc.request_queue.get(block=True, timeout=0.05) except queue.Empty: - request = None # Issue 32207: calling handle_tk_events here adds spurious # queue.Empty traceback to event handling exceptions. + pass if request: seq, (method, args, kwargs) = request ret = method(*args, **kwargs) @@ -185,6 +186,10 @@ def main(del_exitfunc=False): except KeyboardInterrupt: if quitting: exit_now = True + elif request: + # Interrupted while executing a request, as when debugging. + print_exception() + rpc.response_queue.put((seq, None)) continue except SystemExit: capture_warnings(False) diff --git a/Misc/NEWS.d/next/IDLE/2026-09-15-15-46-35.gh-issue-71136.vwGO0v.rst b/Misc/NEWS.d/next/IDLE/2026-09-15-15-46-35.gh-issue-71136.vwGO0v.rst new file mode 100644 index 000000000000000..794a51b2b32e857 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2026-09-15-15-46-35.gh-issue-71136.vwGO0v.rst @@ -0,0 +1,2 @@ +Fix a hang of the IDLE Shell when code run under the debugger raises +:exc:`KeyboardInterrupt`.