Why doesn't my finaliser run here?
Oscar Benjamin
oscar.j.benjamin at gmail.com
Sun Sep 4 08:58:11 EDT 2016
On 4 Sep 2016 13:27, "Steve D'Aprano" <steve+python at 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
More information about the Python-list
mailing list