Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import linecache
import queue
import sys
import signal
import textwrap
import time
import traceback
Expand Down Expand Up @@ -106,6 +107,7 @@ def handle_tk_events(tcl=tcl):
exit_now = False
quitting = False
interruptable = False
finish = False

def main(del_exitfunc=False):
"""Start the Python execution server in a subprocess
Expand All @@ -128,6 +130,8 @@ def main(del_exitfunc=False):
global exit_now
global quitting
global no_exitfunc
global main_thread
main_thread = threading.get_ident()
no_exitfunc = del_exitfunc
#time.sleep(15) # test subprocess not responding
try:
Expand Down Expand Up @@ -570,9 +574,10 @@ def __init__(self, rpchandler):
self.locals = {}

def runcode(self, code):
global interruptable
global interruptable, finish
try:
self.user_exc_info = None
finish = False
interruptable = True
try:
exec(code, self.locals)
Expand Down Expand Up @@ -601,11 +606,22 @@ def runcode(self, code):
self.rpchandler.interp.open_remote_stack_viewer()
else:
flush_stdout()
finally:
finish = True

def interrupt_the_server(self):
if interruptable:
thread.interrupt_main()

# See issue 29926, fallback when interrupt_main doesn't work
def _interrupt_by_signal_pthread():
if not finish:
try:
signal.pthread_kill(main_thread, signal.SIGINT)
except AttributeError:
pass
threading.Timer(0.2, _interrupt_by_signal_pthread).start()

def start_the_debugger(self, gui_adap_oid):
return debugger_r.start_debugger(self.rpchandler, gui_adap_oid)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IDLE Shell no longer ignores Ctrl+C when an interpreter waits on a
blocking function. Patch by Louie Lu.