How to make a pdb set_trace the first breakpoint
<p>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:</p>

<pre><code>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()
</code></pre>

<p>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. </p>

<p>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?</p>

<p>You need not modify your code (by adding calls to <code>pdb.set_trace()</code>) in order to debug it with <code>pdb</code> (the advice to do that has always seemed misguided to me). <a href="http://stackoverflow.com/q/34914704/5384908">This question</a> is another example of a problem this approach can cause.</p>

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

python pdb