diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-12-04 19:10:55 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-12-04 19:10:55 (GMT) |
commit | de67a4233cf175133e5baac9153315393e668357 (patch) | |
tree | d5c99fc29993e42d17fcb7841b347d7be928589d | |
parent | 8dbd421b4d48d31891d159d8c581ea7c0b15226d (diff) | |
parent | 1dfb5c1cf3aac0a42b157631a0e8d274e5be8c6f (diff) | |
download | cpython-de67a4233cf175133e5baac9153315393e668357.zip cpython-de67a4233cf175133e5baac9153315393e668357.tar.gz cpython-de67a4233cf175133e5baac9153315393e668357.tar.bz2 |
Merge 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
@@ -1031,8 +1031,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 0f7a984..4e543dd 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -667,6 +667,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) @@ -153,6 +153,9 @@ Core and Builtins Library ------- +- Issue #13120: Allow to call pdb.set_trace() from thread. + Patch by Ilya Sandler. + - Issue #16585: Make CJK encoders support error handlers that return bytes per PEP 383. |