[Python-Dev] PEP 442: Safe object finalization

Richard Oudkerk shibturn at gmail.com
Sat May 18 15:56:38 CEST 2013

On 18/05/2013 9:59am, Antoine Pitrou wrote:
> This PEP proposes to turn CI disposal into the following sequence (new
> steps are in bold):
> 1. Weakrefs to CI objects are cleared, and their callbacks called. At
>     this point, the objects are still safe to use.
> 2. **The finalizers of all CI objects are called.**

How do you know that one of the finalizers will not do something which 
causes another to fail?

Presumably the following would cause an AttributeError to be printed:

     class Node:
         def __init__(self):
             self.next = None
         def __del__(self):
             print(self, self.next)
             del self.next                   # break Node object

     a = Node()
     b = Node()
     a.next = b
     b.next = a
     del a, b

Are there are less contrived examples which will cause errors where 
currently there are none?


More information about the Python-Dev mailing list