Last active
December 9, 2015 09:19
-
-
Save rhizoome/ce3718e5119c6e7e9b3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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