https://github.com/python/cpython/commit/ca42f6a118df9458cee5e37528147339f570671e
commit: ca42f6a118df9458cee5e37528147339f570671e
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: terryjreedy <[email protected]>
date: 2026-09-26T02:29:30Z
summary:

[3.13] gh-71136: Fix IDLE Shell hang after KeyboardInterrupt under the debugger 
(GH-157566) (#158206)

gh-71136: Fix IDLE Shell hang after KeyboardInterrupt under the debugger 
(GH-157566)

Debugging 'raise KeyboardInterrupt' in debugged code no longer hangs IDLE 
forever.  The response is similar to without the debugger.

---------


(cherry picked from commit ee1bbf037ff74ff3c5e7b95623d78aa34744cd49)

Co-authored-by: Serhiy Storchaka <[email protected]>

files:
A Misc/NEWS.d/next/IDLE/2026-09-15-15-46-35.gh-issue-71136.vwGO0v.rst
M Lib/idlelib/run.py

diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index c69060620f5f9f..48e8f3c4605fc0 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -164,6 +164,7 @@ def main(del_exitfunc=False):
                     ).start()
 
     while True:
+        request = None
         try:
             if exit_now:
                 try:
@@ -174,9 +175,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)
@@ -186,6 +187,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 00000000000000..794a51b2b32e85
--- /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`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to