Why Nostr? What is Njump?
2024-12-22 18:27:22

Hanno Rein on Nostr: Can someone help me understand what's going on with reference counts during a #python ...

Can someone help me understand what's going on with reference counts during a #python exception in a #jupyter notebook?

# Cell 1
import sys
class Test:
def exception(self):
raise ValueError("test")
t = Test()
print(sys.getrefcount(t)) # -> 2
t.exception()
# Cell 2
print(sys.getrefcount(t)) # -> 4

Why does the reference count remain increased after an exception? Is there a way to avoid this?
Author Public Key
npub1rqq5rv8tr2yu3cssea82js0mwrms5k3jm9h49d2k6tuhew8w9khsjr7gnu