-
-
Save Bogdanp/cc59e34fdd60b9d163df0a43e4621dae 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 time | |
class Message: | |
def __init__(self): | |
self._exception = None | |
def __del__(self): | |
print("running!") | |
def f(): | |
raise RuntimeError("test") | |
def g(): | |
m = Message() | |
d = {"a": m} # putting something else on the stack with a reference to m | |
try: | |
f() | |
except Exception as e: | |
m._exception = e | |
g() | |
print("pre sleep 1") | |
time.sleep(1) | |
gc.collect() | |
print("after sleep 1") | |
time.sleep(1) | |
print("after sleep 2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yields:
on Python 3.8 on macOS.