title: How do I know where is a function was executed in Python?
body: <p>Let's imagine, I've got a module <code>foo.py</code> with declared a function <code>foofunc</code>:</p>
  
  <pre><code>def foofunc():
      # smart things
      return
  </code></pre>
  
  <p>And two different modules — <code>bar.py</code> and <code>spam.py</code>, where exists code which directly executes the function from <code>foo</code> module.</p>
  
  <pre><code># `bar` module. All rights reserved.
  
  from foo import foofunc
  
  
  def run_foofunc():
       return foofunc()
  </code></pre>
  
  <p>The same thing in another module:</p>
  
  <pre><code># `spam` module. All rights reserved.
  
  from foo import foofunc
  
  
  def run_foofunc():
      return foofunc()
  </code></pre>
  
  <p>I need to know where is executed the function without knowledge of possible places. Something like:</p>
  
  <pre><code>def foofunc():
      print inspect.executedfrom()
  </code></pre>
  
  <p>Will do something like that in standard output</p>
  
  <pre><code>&lt;pack.bar.run_foofunc&gt;
  </code></pre>
  
  <p>Does it something similar in real world?</p>