Skip to content

Commit 514cfe7

Browse files
gh-138641: Ignore set_trace() when we are already in pdb (#159918)
1 parent 8753370 commit 514cfe7

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎Lib/bdb.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ def set_trace(self, frame=None):
601601
602602
If frame is not specified, debugging starts from caller's frame.
603603
"""
604+
605+
if self.enterframe is not None:
606+
# If self.enterframe is not None, it means we are already in
607+
# dispatched functions. Tracing is disabled when calling a
608+
# trace function, so we just skip this set_trace() call.
609+
return
610+
604611
self.stop_trace()
605612
if frame is None:
606613
frame = sys._getframe().f_back

‎Lib/test/test_pdb.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4979,6 +4979,18 @@ def foo():
49794979
stdout, _ = self._run_script(script, commands)
49804980
self.assertIn("42", stdout)
49814981

4982+
def test_nested_set_trace(self):
4983+
# Calling breakpoint() in pdb prompt should just be ignored.
4984+
script = "breakpoint()"
4985+
commands = """
4986+
breakpoint()
4987+
p 40 + 2
4988+
c
4989+
"""
4990+
stdout, stderr = self._run_script(script, commands)
4991+
self.assertIn('42', stdout)
4992+
self.assertEqual(stderr, '')
4993+
49824994
def test_readline_not_imported(self):
49834995
"""GH-138860
49844996
Directly or indirectly importing readline might deadlock a subprocess
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ignore :func:`pdb.set_trace` when called directly at the :mod:`pdb` prompt.

0 commit comments

Comments
 (0)