Skip to content

Instantly share code, notes, and snippets.

@ganwell
Last active December 9, 2015 09: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 ganwell/ce3718e5119c6e7e9b3e to your computer and use it in GitHub Desktop.
Save ganwell/ce3718e5119c6e7e9b3e to your computer and use it in GitHub Desktop.
import gc
import asyncio
import traceback
import inspect
loop = asyncio.get_event_loop()
class A(object):
def __del__(self):
print("Del A")
async def test(self):
res = asyncio.ensure_future(self.error())
try:
await res
except Exception:
pass
async def error(self):
raise Exception()
a = A()
loop.run_until_complete(a.test())
loop.close()
print("Frames which refer to a:")
print("---")
[traceback.print_stack(x) for x in gc.get_referrers(a) if inspect.isframe(x)]
print("---")
print("Refcounting:")
a = None
print("GC:")
gc.collect()
# Frames which refer to a:
# ---
# File "bug.py", line 17, in test
# pass
# File "bug.py", line 20, in error
# raise Exception()
# ---
# Refcounting:
# GC:
# Del A
# Python ending:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment