Pb with __del__ and inheritence

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Mar 7 06:24:37 EST 2007


En Wed, 07 Mar 2007 07:35:05 -0300, Erwan Adam <erwan.adam at cea.fr>  
escribió:

> Can someone reproduce this bug ... I use :
Same on 2.5 Windows.

> class XObject(object):
>
>      def __del__(self):
>          print "XObject.__del__"
>          return
>
>      pass
>
> class A(XObject):
>
>      def __del__(self):
>          print "A.__del__"
>          XObject.__del__(self)
>          return
>
>      pass
>
> aaa = A()
> ------
> A.__del__
> Exception exceptions.AttributeError: "'NoneType' object has no attribute
> '__del__'" in <bound method A.__del__ of <__main__.A object at
> 0xb7bb124c>> ignored

Print XObject inside A.__del__ and you can see that it is None. That means  
that the XObject reference was set to None *before* aaa was deleted.  
Values inside the module namespace are set to None when it's destroyed (to  
break possible reference cycles, I presume). I can't find any place in the  
docs that guarantees any ordering on the object deletion, so I don't  
consider this a "bug". See the big notes on the __del__ method docs.

If you *really* must do some cleanup on A.__del__, you can't trust on  
*any* globals, and you must store a reference to anything needed inside  
__del__

-- 
Gabriel Genellina




More information about the Python-list mailing list