Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 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
20 changes: 20 additions & 0 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2647,6 +2647,16 @@ def set_trace(*, header=None, commands=None):
just before debugging begins. *commands* is an optional list of
pdb commands to run when the debugger starts.
"""
# Check if we're already in a pdb session by examining the call stack
frame = sys._getframe()
while frame:
if frame.f_code.co_name == 'interaction' and frame.f_code.co_filename.endswith('pdb.py'):
# We're already in a pdb session, just print a message and return
print("*** Nested breakpoint calls are not supported. "
"Already running in the debugger.", file=sys.stderr)
return
frame = frame.f_back

if Pdb._last_pdb_instance is not None:
pdb = Pdb._last_pdb_instance
else:
Expand All @@ -2662,6 +2672,16 @@ async def set_trace_async(*, header=None, commands=None):
if they enter the debugger with this function. Otherwise it's the same
as set_trace().
"""
# Check if we're already in a pdb session by examining the call stack
frame = sys._getframe()
while frame:
if frame.f_code.co_name == 'interaction' and frame.f_code.co_filename.endswith('pdb.py'):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems can into a function

# We're already in a pdb session, just print a message and return
print("*** Nested breakpoint calls are not supported. "
"Already running in the debugger.", file=sys.stderr)
return
frame = frame.f_back

if Pdb._last_pdb_instance is not None:
pdb = Pdb._last_pdb_instance
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prevent error when calling :func:`breakpoint` inside a :mod:`pdb` debugging session.
Nested breakpoint calls now display a helpful error message instead of causing error.
Loading