code: def print_stack(sig, frame):
      
      if _debug: print_stack._debug("print_stack %r %r", sig, frame)
      global running, deferredFns, sleeptime
  
      sys.stderr.write("==== USR1 Signal, %s\n" % time.strftime("%d-%b-%Y %H:%M:%S"))
  
      sys.stderr.write("---------- globals\n")
      sys.stderr.write("    running: %r\n" % (running,))
      sys.stderr.write("    deferredFns: %r\n" % (deferredFns,))
      sys.stderr.write("    sleeptime: %r\n" % (sleeptime,))
  
      sys.stderr.write("---------- stack\n")
      traceback.print_stack(frame)
  
      # make a list of interesting frames
      flist = []
      f = frame
      while f.f_back:
          flist.append(f)
          f = f.f_back
  
      # reverse the list so it is in the same order as print_stack
      flist.reverse()
      for f in flist:
          sys.stderr.write("---------- frame: %s\n" % (f,))
          for k, v in f.f_locals.items():
              sys.stderr.write("    %s: %r\n" % (k, v))
  
      sys.stderr.flush()
docs: Signal handler to print a stack trace and some interesting values.