Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 539ee5d

Browse files
committed
Issue #13120: Allow to call pdb.set_trace() from thread.
Patch by Ilya Sandler.
1 parent 86067c2 commit 539ee5d

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

Lib/pdb.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,15 @@ def do_continue(self, arg):
955955
Continue execution, only stop when a breakpoint is encountered.
956956
"""
957957
if not self.nosigint:
958-
self._previous_sigint_handler = \
959-
signal.signal(signal.SIGINT, self.sigint_handler)
958+
try:
959+
self._previous_sigint_handler = \
960+
signal.signal(signal.SIGINT, self.sigint_handler)
961+
except ValueError:
962+
# ValueError happens when do_continue() is invoked from
963+
# a non-main thread in which case we just continue without
964+
# SIGINT set. Would printing a message here (once) make
965+
# sense?
966+
pass
960967
self.set_continue()
961968
return 1
962969
do_c = do_cont = do_continue

Lib/test/test_pdb.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,33 @@ def bar():
664664
any('main.py(5)foo()->None' in l for l in stdout.splitlines()),
665665
'Fail to step into the caller after a return')
666666

667+
def test_issue13210(self):
668+
# invoking "continue" on a non-main thread triggered an exception
669+
# inside signal.signal
670+
671+
with open(support.TESTFN, 'wb') as f:
672+
f.write(textwrap.dedent("""
673+
import threading
674+
import pdb
675+
676+
def start_pdb():
677+
pdb.Pdb().set_trace()
678+
x = 1
679+
y = 1
680+
681+
t = threading.Thread(target=start_pdb)
682+
t.start()""").encode('ascii'))
683+
cmd = [sys.executable, '-u', support.TESTFN]
684+
proc = subprocess.Popen(cmd,
685+
stdout=subprocess.PIPE,
686+
stdin=subprocess.PIPE,
687+
stderr=subprocess.STDOUT,
688+
)
689+
self.addCleanup(proc.stdout.close)
690+
stdout, stderr = proc.communicate(b'cont\n')
691+
self.assertNotIn('Error', stdout.decode(),
692+
"Got an error running test script under PDB")
693+
667694
def tearDown(self):
668695
support.unlink(support.TESTFN)
669696

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ Core and Builtins
175175
Library
176176
-------
177177

178+
- Issue #13120: Allow to call pdb.set_trace() from thread.
179+
Patch by Ilya Sandler.
180+
178181
- Issue #10182: The re module doesn't truncate indices to 32 bits anymore.
179182
Patch by Serhiy Storchaka.
180183

0 commit comments

Comments
 (0)