super not working in __del__ ?
Fredrik Lundh
fredrik at pythonware.com
Wed Feb 16 01:59:55 EST 2005
Christopher J. Bottaro wrote:
>I get this exception when I run the following code:
>
> Exception exceptions.TypeError: 'super() argument 1 must be type, not None'
> in <bound method Txrposdn.__del__ of <__main__.Txrposdn object at
> 0xf6f7118c>> ignored
reading the documentation never hurts:
http://docs.python.org/ref/customization.html
"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."
in this case,
def __del__(self):
super(self.__class__, self).__del__()
should do the trick.
in other cases, you may have to store references to important globals to class
or instance variables, or in bound arguments:
def __del__(self, name=name):
name(...)
or you could just wrap the cleanup in a try/except clause, since this only happens
when the interpreter is shutting down.
for cleanup details, see:
http://www.python.org/doc/essays/cleanup.html
</F>
More information about the Python-list
mailing list