From 9f316bd9684d27b7e21fbf43ca86dc5e65dac4af Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 19 Apr 2019 12:43:51 +0200 Subject: [PATCH] pdb: restore SIGINT handler in sigint_handler already MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this, and additional SIGINT while waiting for the next statement (e.g. during `time.sleep`) will stop at `sigint_handler`. With this patch: > …/t-pdb-sigint-in-sleep.py(10)() -> sleep() (Pdb) c ^C Program interrupted. (Use 'cont' to resume). ^CKeyboardInterrupt > …/t-pdb-sigint-in-sleep.py(6)sleep() -> time.sleep(10) (Pdb) Without this patch: > …/t-pdb-sigint-in-sleep.py(10)() -> sleep() (Pdb) c ^C Program interrupted. (Use 'cont' to resume). ^C--Call-- > …/cpython/Lib/pdb.py(188)sigint_handler() -> def sigint_handler(self, signum, frame): (Pdb) --- Lib/pdb.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/pdb.py b/Lib/pdb.py index f5d33c27fc1d919..4e852fa9731c80c 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -186,6 +186,9 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, # defining a list def sigint_handler(self, signum, frame): + if Pdb._previous_sigint_handler: + signal.signal(signal.SIGINT, Pdb._previous_sigint_handler) + Pdb._previous_sigint_handler = None if self.allow_kbdint: raise KeyboardInterrupt self.message("\nProgram interrupted. (Use 'cont' to resume).")