[Numpy-discussion] usage of __del__ in python classes
Wed Jan 31 21:39:04 CST 2007
Before I start I want to admit that I don't understand much about
this. I just saw that the memmap class defines __del__ and that I had
problems in the past when I added a 'def __del__' to a class of mine.
So here is a quote, I would like to know if this is "standard
knowledge" on this list or not.
# I found the info originally here: http://arctrix.com/nas/python/gc/
# Circular references which are garbage are detected when the
optional cycle detector is enabled (it's on by default), but can only
be cleaned up if there are no Python-level __del__() methods involved.
Refer to the documentation for the 'gc' module for more information
about how __del__() methods are handled by the cycle detector,
particularly the description of the garbage value. Notice: [warning]
Due to the precarious circumstances under which __del__() methods are
invoked, exceptions that occur during their execution are ignored, and
a warning is printed to sys.stderr instead. Also, when __del__() is
invoked in response to a module being deleted (e.g., when execution of
the program is done), other globals referenced by the __del__() method
may already have been deleted. For this reason, __del__() methods
should do the absolute minimum needed to maintain external invariants.
More information about the Numpy-discussion