Skip to content

Instantly share code, notes, and snippets.

@aaronasterling
Created December 22, 2010 12:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronasterling/751449 to your computer and use it in GitHub Desktop.
Save aaronasterling/751449 to your computer and use it in GitHub Desktop.
import gc
import sys
def giveupthefunc():
code = sys._getframe(1).f_code
functype = type(lambda: 0)
for func in gc.get_referrers(code):
if type(func) is functype and getattr(func, "func_code", None) is code:
return func
def makefunc():
def func():
return giveupthefunc()
return func
funcs = [makefunc() for _ in xrange(10)]
for f in funcs:
print "id(f): {0}, id(f()): {1}".format(id(f), id(f()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment