From 7ce3928fb8ab2b0f0b4f4ca22485b47631872b57 Mon Sep 17 00:00:00 2001 From: Louie Lu Date: Wed, 28 Jun 2017 16:44:20 +0800 Subject: [PATCH 1/3] bpo-29926: IDLE: Fix blocking function ignore SIGINT Co-Authored-By: Martin Panter --- Lib/idlelib/run.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 9f6604bb0acc58..4e061a58407e94 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -2,6 +2,7 @@ import linecache import queue import sys +import signal import time import traceback import _thread as thread @@ -86,6 +87,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 @@ -108,6 +110,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: @@ -439,7 +443,6 @@ def decode_interrupthook(self): quitting = True thread.interrupt_main() - class Executive(object): def __init__(self, rpchandler): @@ -449,9 +452,10 @@ def __init__(self, rpchandler): self.autocomplete = autocomplete.AutoComplete() def runcode(self, code): - global interruptable + global interruptable, finish try: self.usr_exc_info = None + finish = False interruptable = True try: exec(code, self.locals) @@ -472,11 +476,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) From a1b5a2e30fc7433651eae887d3364b4a7ed7f965 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Mon, 25 Jan 2021 08:04:54 -0500 Subject: [PATCH 2/3] Update run.py --- Lib/idlelib/run.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 4e061a58407e94..375d8faf333d4e 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -3,6 +3,7 @@ import queue import sys import signal +import textwrap import time import traceback import _thread as thread @@ -443,7 +444,7 @@ def decode_interrupthook(self): quitting = True thread.interrupt_main() -class Executive(object): +class Executive: def __init__(self, rpchandler): self.rpchandler = rpchandler From cdbad974be198d03238016f29f3881ecb4b095bc Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 3 Feb 2023 13:45:48 +0400 Subject: [PATCH 3/3] Add a NEWS entry --- .../next/IDLE/2023-02-03-13-39-00.gh-issue-74112.9tqu39.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2023-02-03-13-39-00.gh-issue-74112.9tqu39.rst diff --git a/Misc/NEWS.d/next/IDLE/2023-02-03-13-39-00.gh-issue-74112.9tqu39.rst b/Misc/NEWS.d/next/IDLE/2023-02-03-13-39-00.gh-issue-74112.9tqu39.rst new file mode 100644 index 00000000000000..c237af2b7b3ea0 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2023-02-03-13-39-00.gh-issue-74112.9tqu39.rst @@ -0,0 +1,2 @@ +IDLE Shell no longer ignores Ctrl+C when an interpreter waits on a +blocking function. Patch by Louie Lu.