Skip to content

Commit ee1bbf0

Browse files
serhiy-storchakamlouieluclaude
authored
gh-71136: Fix IDLE Shell hang after KeyboardInterrupt under the debugger (#157566)
Debugging 'raise KeyboardInterrupt' in debugged code no longer hangs IDLE forever. The response is similar to without the debugger. --------- Co-authored-by: Louie Lu <git@louie.lu> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a000129 commit ee1bbf0

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎Lib/idlelib/run.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def main(del_exitfunc=False):
164164
).start()
165165

166166
while True:
167+
request = None
167168
try:
168169
if exit_now:
169170
try:
@@ -174,9 +175,9 @@ def main(del_exitfunc=False):
174175
try:
175176
request = rpc.request_queue.get(block=True, timeout=0.05)
176177
except queue.Empty:
177-
request = None
178178
# Issue 32207: calling handle_tk_events here adds spurious
179179
# queue.Empty traceback to event handling exceptions.
180+
pass
180181
if request:
181182
seq, (method, args, kwargs) = request
182183
ret = method(*args, **kwargs)
@@ -186,6 +187,10 @@ def main(del_exitfunc=False):
186187
except KeyboardInterrupt:
187188
if quitting:
188189
exit_now = True
190+
elif request:
191+
# Interrupted while executing a request, as when debugging.
192+
print_exception()
193+
rpc.response_queue.put((seq, None))
189194
continue
190195
except SystemExit:
191196
capture_warnings(False)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a hang of the IDLE Shell when code run under the debugger raises
2+
:exc:`KeyboardInterrupt`.

0 commit comments

Comments
 (0)