diff options
author | Xavier de Gaye <xdegaye@users.sourceforge.net> | 2016-10-12 18:13:24 (GMT) |
---|---|---|
committer | Xavier de Gaye <xdegaye@users.sourceforge.net> | 2016-10-12 18:13:24 (GMT) |
commit | 10e54aeaa234f2806b367c66e3fb4ac6568b39f6 (patch) | |
tree | e7b19ba4ccec369878324c2e05690d94e23bfe4c /Lib/pdb.py | |
parent | fd28cbef4b1a1b85f8fc6d936a8916302abdf171 (diff) | |
download | cpython-10e54aeaa234f2806b367c66e3fb4ac6568b39f6.zip cpython-10e54aeaa234f2806b367c66e3fb4ac6568b39f6.tar.gz cpython-10e54aeaa234f2806b367c66e3fb4ac6568b39f6.tar.bz2 |
Issue #20766: Fix references leaked by pdb in the handling of SIGINT handlers.
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-x | Lib/pdb.py | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -134,6 +134,8 @@ line_prefix = '\n-> ' # Probably a better default class Pdb(bdb.Bdb, cmd.Cmd): + _previous_sigint_handler = None + def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, nosigint=False): bdb.Bdb.__init__(self, skip=skip) @@ -187,8 +189,6 @@ class Pdb(bdb.Bdb, cmd.Cmd): self.message("\nProgram interrupted. (Use 'cont' to resume).") self.set_step() self.set_trace(frame) - # restore previous signal handler - signal.signal(signal.SIGINT, self._previous_sigint_handler) def reset(self): bdb.Bdb.reset(self) @@ -337,6 +337,10 @@ class Pdb(bdb.Bdb, cmd.Cmd): (expr, newvalue, oldvalue)) def interaction(self, frame, traceback): + # Restore the previous signal handler at the Pdb prompt. + if Pdb._previous_sigint_handler: + signal.signal(signal.SIGINT, Pdb._previous_sigint_handler) + Pdb._previous_sigint_handler = None if self.setup(frame, traceback): # no interaction desired at this time (happens if .pdbrc contains # a command like "continue") @@ -1037,7 +1041,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): """ if not self.nosigint: try: - self._previous_sigint_handler = \ + Pdb._previous_sigint_handler = \ signal.signal(signal.SIGINT, self.sigint_handler) except ValueError: # ValueError happens when do_continue() is invoked from |