title: In Python, how can I get the global variables that are used in a function?
body: <p>I'm trying to collect info on crashes and I am having trouble figuring out how to get the globals that are being used in the crashed function.</p>
  
  <pre><code>import inspect
  
  fun = 222
  other = "junk"
  
  def test():
      global fun
      harold = 888 + fun
      try:
          harold/0
      except:
          frames = inspect.trace()
          print "Local variables:"
          print frames[0][0].f_locals
  
          print "All global variables, not what I want!"
          print frames[0][0].f_globals
  
  test()
  </code></pre>
  
  <p>test() only uses "fun" but f_globals gives all the available globals.  Is there some way to get just the globals that are being used by this function?</p>