[Python-checkins] cpython (merge 3.2 -> 3.3): Merge issue #13120: Allow to call pdb.set_trace() from thread.
andrew.svetlov
python-checkins at python.org
Tue Dec 4 20:11:09 CET 2012
http://hg.python.org/cpython/rev/678dba60c12d
changeset: 80722:678dba60c12d
branch: 3.3
parent: 80715:6f8b5336beae
parent: 80721:708586792eec
user: Andrew Svetlov <andrew.svetlov at gmail.com>
date: Tue Dec 04 21:10:20 2012 +0200
summary:
Merge issue #13120: Allow to call pdb.set_trace() from thread.
Patch by Ilya Sandler.
files:
Lib/pdb.py | 11 +++++++++--
Lib/test/test_pdb.py | 27 +++++++++++++++++++++++++++
Misc/NEWS | 3 +++
3 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/Lib/pdb.py b/Lib/pdb.py
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1031,8 +1031,15 @@
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
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -667,6 +667,33 @@
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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -104,6 +104,9 @@
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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list