diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-12-04 21:08:28 +0200 |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-12-04 21:08:28 +0200 |
commit | 539ee5da6fb2a56869e6c6f4401300b4d5906d76 (patch) | |
tree | 98b32fae910ccb41a333319b65fcd19343cedb87 | |
parent | 86067c2e17b221ac10c4b4c97030c2cfc44eccaf (diff) | |
download | cpython-git-539ee5da6fb2a56869e6c6f4401300b4d5906d76.tar.gz |
Issue #13120: Allow to call pdb.set_trace() from thread.
Patch by Ilya Sandler.
-rwxr-xr-x | Lib/pdb.py | 11 | ||||
-rw-r--r-- | Lib/test/test_pdb.py | 27 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 39 insertions, 2 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py index 6776a3f4cf..8c7c12b92c 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -955,8 +955,15 @@ class Pdb(bdb.Bdb, cmd.Cmd): Continue execution, only stop when a breakpoint is encountered. """ if not self.nosigint: - self._previous_sigint_handler = \ - signal.signal(signal.SIGINT, self.sigint_handler) + try: + self._previous_sigint_handler = \ + signal.signal(signal.SIGINT, self.sigint_handler) + except ValueError: + # ValueError happens when do_continue() is invoked from + # a non-main thread in which case we just continue without + # SIGINT set. Would printing a message here (once) make + # sense? + pass self.set_continue() return 1 do_c = do_cont = do_continue diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index d28b0425e5..dc2609e0c5 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -664,6 +664,33 @@ class PdbTestCase(unittest.TestCase): any('main.py(5)foo()->None' in l for l in stdout.splitlines()), 'Fail to step into the caller after a return') + def test_issue13210(self): + # invoking "continue" on a non-main thread triggered an exception + # inside signal.signal + + with open(support.TESTFN, 'wb') as f: + f.write(textwrap.dedent(""" + import threading + import pdb + + def start_pdb(): + pdb.Pdb().set_trace() + x = 1 + y = 1 + + t = threading.Thread(target=start_pdb) + t.start()""").encode('ascii')) + cmd = [sys.executable, '-u', support.TESTFN] + proc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + self.addCleanup(proc.stdout.close) + stdout, stderr = proc.communicate(b'cont\n') + self.assertNotIn('Error', stdout.decode(), + "Got an error running test script under PDB") + def tearDown(self): support.unlink(support.TESTFN) @@ -175,6 +175,9 @@ Core and Builtins Library ------- +- Issue #13120: Allow to call pdb.set_trace() from thread. + Patch by Ilya Sandler. + - Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. |