strange __del__ behavior
Bernhard Herzog
bh at intevation.de
Wed Jun 9 14:22:26 EDT 2004
John Hunter <jdhunter at ace.bsd.uchicago.edu> writes:
> For debugging purposes, I would like to know when C instances are
> being deleted; that's why I inserted the __del__ print method. Is
> there any way to get that info w/o defining __del__ and thereby
> screwing up python's garbage collection?
I've sometimes used something like this:
class DelReporter:
def __init__(self, message):
self.message = message
def __del__(self):
print self.message
class C:
def __init__(self):
self.__del = DelReporter("__del__: %r" % self)
Even if a C-instance is part of a cycle, its __del member is not, so
it's __del__ doesn't affect garbage collection.
Bernhard
--
Intevation GmbH http://intevation.de/
Skencil http://sketch.sourceforge.net/
Thuban http://thuban.intevation.org/
More information about the Python-list
mailing list