diff options
author | Xavier de Gaye <xdegaye@users.sourceforge.net> | 2016-10-12 20:18:33 +0200 |
---|---|---|
committer | Xavier de Gaye <xdegaye@users.sourceforge.net> | 2016-10-12 20:18:33 +0200 |
commit | b4474848de1bb75e1ea236751e92b8cfa7654411 (patch) | |
tree | b2de78f2c02a53c941e6b6d51560fdfd3f4785e8 | |
parent | 5a33759fbabb882a930d3346ccfa723bb7f602b9 (diff) | |
parent | 291417da7fc141e4ede93b804b6532460f2cc528 (diff) | |
download | cpython-git-b4474848de1bb75e1ea236751e92b8cfa7654411.tar.gz |
Issue #20766: Merge with 3.6.
-rwxr-xr-x | Lib/pdb.py | 10 | ||||
-rw-r--r-- | Lib/test/test_pdb.py | 23 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 33 insertions, 3 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py index 7eb78b922a..97618b0ff1 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -135,6 +135,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, readrc=True): bdb.Bdb.__init__(self, skip=skip) @@ -189,8 +191,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) @@ -339,6 +339,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") @@ -1039,7 +1043,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 diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 994e088d30..0ea2af5541 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -911,6 +911,29 @@ def test_pdb_next_command_subiterator(): (Pdb) continue """ +def test_pdb_issue_20766(): + """Test for reference leaks when the SIGINT handler is set. + + >>> def test_function(): + ... i = 1 + ... while i <= 2: + ... sess = pdb.Pdb() + ... sess.set_trace(sys._getframe()) + ... print('pdb %d: %s' % (i, sess._previous_sigint_handler)) + ... i += 1 + + >>> with PdbTestInput(['continue', + ... 'continue']): + ... test_function() + > <doctest test.test_pdb.test_pdb_issue_20766[0]>(6)test_function() + -> print('pdb %d: %s' % (i, sess._previous_sigint_handler)) + (Pdb) continue + pdb 1: <built-in function default_int_handler> + > <doctest test.test_pdb.test_pdb_issue_20766[0]>(5)test_function() + -> sess.set_trace(sys._getframe()) + (Pdb) continue + pdb 2: <built-in function default_int_handler> + """ class PdbTestCase(unittest.TestCase): @@ -85,6 +85,9 @@ Core and Builtins Library ------- +- Issue #20766: Fix references leaked by pdb in the handling of SIGINT + handlers. + - Issue #27998: Fixed bytes path support in os.scandir() on Windows. Patch by Eryk Sun. |