Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,13 @@ def set_trace(self, frame=None):

If frame is not specified, debugging starts from caller's frame.
"""

if self.enterframe is not None:
# If self.enterframe is not None, it means we are already in
# dispatched functions. Tracing is disabled when calling a
# trace function, so we just skip this set_trace() call.
return

self.stop_trace()
if frame is None:
frame = sys._getframe().f_back
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4875,6 +4875,18 @@ def foo():
stdout, _ = self._run_script(script, commands)
self.assertIn("42", stdout)

def test_nested_set_trace(self):
# Calling breakpoint() in pdb prompt should just be ignored.
script = "breakpoint()"
commands = """
breakpoint()
p 40 + 2
c
"""
stdout, stderr = self._run_script(script, commands)
self.assertIn('42', stdout)
self.assertEqual(stderr, '')

def test_readline_not_imported(self):
"""GH-138860
Directly or indirectly importing readline might deadlock a subprocess
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore :func:`pdb.set_trace` when called directly at the :mod:`pdb` prompt.
Loading