On 4 Sep 2016 13:27, "Steve D'Aprano" <steve+pyt...@pearwood.info> wrote: > > Why doesn't __del__ run here? > > > class Eggs(object): > def __new__(cls): > instance = object.__new__(cls) > print("instance created successfully") > return instance > def __init__(self): > print("self definitely exists:", self) > raise Exception > def __del__(self): > print("deleting", repr(self)) > > > And an example: > > > py> e = Eggs() > instance created successfully > self definitely exists: <__main__.Eggs object at 0xb7bf21ec> > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "<stdin>", line 8, in __init__ > Exception
Maybe the Exception traceback holds a reference to the object. Also try the example outside of interactive mode since that can hold references. -- Oscar -- https://mail.python.org/mailman/listinfo/python-list