Pb with __del__ and inheritence

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Erwan Adam

    #1

    Pb with __del__ and inheritence

    Hello all,

    Can someone reproduce this bug ... I use :

    [adam@is111902 /home/adam/Work/Python]python
    Python 2.4.3 (#2, Sep 18 2006, 21:07:35)
    [GCC 4.1.1 20060724 (prerelease) (4.1.1-3mdk)] on linux2
    Type "help", "copyright" , "credits" or "license" for more information.
    >>>
    First test :

    [adam@is111902 /home/adam/Work/Python]cat bug_del.py && echo "------"
    && python bug_del.py

    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

    a = A()
    ------
    A.__del__
    XObject.__del__
    [adam@is111902 /home/adam/Work/Python]>

    Everything is ok ... now I just replace "a = A()" by "aaa = A()":

    [adam@is111902 /home/adam/Work/Python]cat bug_del.py && echo "------"
    && python bug_del.py

    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.Attr ibuteError: "'NoneType' object has no attribute
    '__del__'" in <bound method A.__del__ of <__main__.A object at
    0xb7bb124c>igno red
    [adam@is111902 /home/adam/Work/Python]>

    !!!


    Thanks in advance,

    E.A.
  • Gabriel Genellina

    #2
    Re: Pb with __del__ and inheritence

    En Wed, 07 Mar 2007 07:35:05 -0300, Erwan Adam <erwan.adam@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.Attr ibuteError: "'NoneType' object has no attribute
    '__del__'" in <bound method A.__del__ of <__main__.A object at
    0xb7bb124c>igno red
    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

    Comment

    Working...