[Python-Dev] __traceback__ and reference cycles

Tim Peters tim.peters at gmail.com
Tue Aug 9 05:02:59 CEST 2005

[Brett Cannon]
> Wasn't there talk of getting rid of __del__ a little while ago and
> instead use weakrefs to functions to handle cleaning up?

There was from me, yes, with an eye toward P3K.

> Is that still feasible?

It never was, really.  The combination of finalizers, cycles and
resurrection is a freakin' mess, "even in theory".  The way things are
right now, Python's weakref gc endcase behavior is even more
mystically implementation-driven than its __del__ gc endcase behavior,
and nobody has had time to try to dream up a cleaner approach.

> And if so, would this alleviate the problem?

Absolutely <wink>.  The underlying reason for optimism is that

    weakrefs in Python are designed to, at worst, let *other* objects
    learn that a given object has died, via a callback function.  The weakly
    referenced object itself is not passed to the callback, and the presumption
    is that the weakly referenced object is unreachable trash at the time the
    callback is invoked.

IOW, resurrection was "obviously" impossible, making endcase life very
much simpler.  That paragraph is from Modules/gc_weakref.txt, and you
can read there all about why optimism hasn't work yet ;-)

More information about the Python-Dev mailing list