Skip to content

Instantly share code, notes, and snippets.

@adeak

adeak/gc_hack.py Secret

Created June 7, 2019 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeak/fa632e3bb223f21f8ed582cf77e09cf0 to your computer and use it in GitHub Desktop.
Save adeak/fa632e3bb223f21f8ed582cf77e09cf0 to your computer and use it in GitHub Desktop.
class CM:
def __enter__(self):
return self
def __exit__(self, *args):
print('hello world')
with CM() as cm:
import gc
gc.get_referrers(cm)[0].__func__.__code__ = (lambda self, *args: print('goodbye world')).__code__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment