Amaury Forgeot d'Arc <amaur...@gmail.com> added the comment:

Normally you should never call __del__, OTOH the issue is the same with a class 
like::

class A:
    def close(self):
        self.close()
    def __del__(self):
        self.close()

The problem is not with _infinite_ recursion, though; a depth of 47 is enough 
(but 46 won't show the problem)::

class A:
    def __del__(self):
        self.recurse(47)
    def recurse(self, n):
        if n:
            self.recurse(n-1)
        else:
            raise ValueError

Hint: PyTrash_UNWIND_LEVEL is defined to 50; I checked that recompiling Python 
with a different value also changes the necessary recursion depth.

There is some nasty interaction between the "Trashcan mechanism" and 
resurrected objects stored in deep structures. A list is enough, no need to 
involve frames and exceptions::

class C:
    def __del__(self):
        print ".",
        x = self
        for i in range(49):    # PyTrash_UNWIND_LEVEL-1
            x = [x]
l = [C()]
del l

----------
nosy: +amaury.forgeotdarc

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10794>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to