0

I have pdb.set_trace() in two spots of my code. The problem is that I get multiple stops in the second area when I want it to start somewhere specific. Here is an example:

def function():
   #some code in here
   pdb.set_trace()
   #some more code

def main():
   #some code
   function()

   #come more code
   function()

   #the code I care about
   pdb.set_trace()
   function()

The problem here is that it will stop in function twice before actually getting to the actual set_trace I want to which first stops inside main and then to function.

This isn't a big deal but in a real setting I get 100s of calls to inside of 'function' before getting to the 'main' set_trace(). Is there a way to specify the first set_trace() or ignore all calls to set_trace until I get to the one I want?

1 Answers1

0

You need not modify your code (by adding calls to pdb.set_trace()) in order to debug it with pdb (the advice to do that has always seemed misguided to me). This question is another example of a problem this approach can cause.

If you invoke pdb on a version of your code with no calls to pdb.set_trace() and use pdb's break command to set breakpoints wherever you might otherwise have added calls to pdb.set_trace(), you can use pdb's disable command when you no longer want a breakpoint to take effect.

Community
  • 1
  • 1
Eirik Fuller
  • 1,454
  • 11
  • 9