История изменений
Исправление lu4nik, (текущая версия) :
https://docs.python.org/3/reference/datamodel.html#object.__del__
«It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits.»
«Note del x doesn’t directly call x.__del__() — the former decrements the reference count for x by one, and the latter is only called when x’s reference count reaches zero.»
«CPython implementation detail: It is possible for a reference cycle to prevent the reference count of an object from going to zero.»
Согласно доке, это НЕ деструктор как он понимается, например, в С++. Кстати, раз исключения в __del__ игнорируются, это открывает возможность для многих незаметных багов, видимых при использовании __enter__/__exit__.
Исходная версия lu4nik, :
https://docs.python.org/3/reference/datamodel.html#object.__del__
«It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits.»
«Note del x doesn’t directly call x.__del__() — the former decrements the reference count for x by one, and the latter is only called when x’s reference count reaches zero.»
«CPython implementation detail: It is possible for a reference cycle to prevent the reference count of an object from going to zero.»
Согласно доке, это НЕ деструктор как он понимается, например, в С++. Кстати, раз исключения в __del__ не ловятся, это открывает возможность для многих незаметных багов, видимых при использовании __enter__/__exit__.