title: Efficient way to determine whether a particular function is on the stack in Python
body: <p>For debugging, it is often useful to tell if a particular function is higher up on the call stack. For example, we often only want to run debugging code when a certain function called us.</p>
  
  <p>One solution is to examine all of the stack entries higher up, but it this is in a function that is deep in the stack and repeatedly called, this leads to excessive overhead. The question is to find a method that allows us to determine if a particular function is higher up on the call stack in a way that is reasonably efficient.</p>
  
  <p><strong>Similar</strong></p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1034688/is-it-possible-to-get-the-function-objects-on-the-execution-stack-from-the-frame">Obtaining references to function objects on the execution stack from the frame object?</a> - This question focuses on obtaining the function objects, rather than determining if we are in a particular function. Although the same techniques could be applied, they may end up being extremely inefficient.</li>
  </ul>