strange behaviour at termination time
Fredrik Lundh
fredrik at pythonware.com
Mon Jun 28 09:48:56 EDT 1999
Fabien COUTANT <fabien.coutant at steria.fr> wrote:
> Basically there is a base class name that I found bound to None,
> which prevents me to call base methods.
>
> I tested it with 1.5.1 on Linux and 1.5.2 on Windows. Was working
> fine with 1.4 in Debian/Linux 1.3.1 till I upgraded to Debian 2.1...
>
> Bug or feature ? Quite annoying if feature...
feature.
1.5.2 does a more aggressive global clean-up when the
interpreter is shut down. this includes zapping modules
and module globals, and replacing them with references
to None.
> More that it, I discovered during testing that sometimes it is correct
> if I change the base class name !
namespaces are dictionaries. changing the name may or may
not change the clean-up order...
> Here is sample code to show it:
>
> ----------------------------------
> class A :
> def __del__ (self) :
> print "A.__del__", self
>
> class B (A) :
> def __del__ (self) :
> print "B.__del__", self, A
> # can't do A.__del__ (self) for example
>
> x = A ()
> y = B ()
> ----------------------------------
>
> In this configuration it should show ok.
> If you change the name of the first class from A to X everywhere
> then X is bound to None in B.__del__ !!!
the only reasonable way to get around this is to explicitly
bind all the names you want in your destructor:
> def __del__ (self, A=A) :
> print "B.__del__", self, A
> A.__del__(self)
(btw, 1.4 probably didn't call B's destructor at all...)
</F>
More information about the Python-list
mailing list