[Python-Dev] PEP 442: Safe object finalization

Eli Bendersky eliben at gmail.com
Sat May 18 15:37:54 CEST 2013

Great PEP, I would really like to see this happen as it defines much saner
semantics for finalization than what we currently have. One small question

 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.**
> 3. **The CI is traversed again to determine if it is still isolated.
>    If it is determined that at least one object in CI is now reachable
>    from outside the CI, this collection is aborted and the whole CI
>    is resurrected.  Otherwise, proceed.**

Not sure if my question is the same as Armin's here, but worth a try: by
saying "the CI is traversed again" do you mean the original objects from
the CI as discovered earlier, or is a new scan being done? What about a new
object entering the CI during step (2)? I.e. the original CI was A->B->A
but now one of the finalizers created some C such that B->C and C->A adding
it to the connected component?

Reading your description in (3) strictly it says: in this case the
collection is aborted. This CI will be disposed next time collection is
run. Is this correct?


> 4. The CI becomes a CT as the GC systematically breaks all
>    known references inside it (using the ``tp_clear`` function).
> 5. Nothing.  All CT objects should have been disposed of in step 4
>    (as a side-effect of clearing references); this collection is
>    finished.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130518/7ab34009/attachment.html>

More information about the Python-Dev mailing list