@@ -2647,6 +2647,16 @@ def set_trace(*, header=None, commands=None):
26472647 just before debugging begins. *commands* is an optional list of
26482648 pdb commands to run when the debugger starts.
26492649 """
2650+ # Check if we're already in a pdb session by examining the call stack
2651+ frame = sys ._getframe ()
2652+ while frame :
2653+ if frame .f_code .co_name == 'interaction' and frame .f_code .co_filename .endswith ('pdb.py' ):
2654+ # We're already in a pdb session, just print a message and return
2655+ print ("*** Nested breakpoint calls are not supported. "
2656+ "Already running in the debugger." , file = sys .stderr )
2657+ return
2658+ frame = frame .f_back
2659+
26502660 if Pdb ._last_pdb_instance is not None :
26512661 pdb = Pdb ._last_pdb_instance
26522662 else :
@@ -2662,6 +2672,16 @@ async def set_trace_async(*, header=None, commands=None):
26622672 if they enter the debugger with this function. Otherwise it's the same
26632673 as set_trace().
26642674 """
2675+ # Check if we're already in a pdb session by examining the call stack
2676+ frame = sys ._getframe ()
2677+ while frame :
2678+ if frame .f_code .co_name == 'interaction' and frame .f_code .co_filename .endswith ('pdb.py' ):
2679+ # We're already in a pdb session, just print a message and return
2680+ print ("*** Nested breakpoint calls are not supported. "
2681+ "Already running in the debugger." , file = sys .stderr )
2682+ return
2683+ frame = frame .f_back
2684+
26652685 if Pdb ._last_pdb_instance is not None :
26662686 pdb = Pdb ._last_pdb_instance
26672687 else :
0 commit comments