Created
December 22, 2010 12:27
-
-
Save aaronasterling/751449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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