Skip to content

Instantly share code, notes, and snippets.

@tigarmo
Created June 13, 2018 11:19
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 tigarmo/f0a71e4fb7396e48064dbceea20dd5ac to your computer and use it in GitHub Desktop.
Save tigarmo/f0a71e4fb7396e48064dbceea20dd5ac to your computer and use it in GitHub Desktop.
import weakref
def inner():
raise RuntimeError()
def outer(obj):
try:
inner()
except RuntimeError as e:
n = RuntimeError()
raise n
def entry(obj):
try:
outer(obj)
except RuntimeError:
return True
return False
class MyObject(object):
pass
def test():
my_object = MyObject()
weak = weakref.ref(my_object)
assert entry(my_object)
my_object = None # Should cause the object to be collected
assert weak() is None
if __name__ == '__main__':
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment