Solution to finalisation problem [Re: fork()]

Tim Peters tim_one at email.msn.com
Thu Jun 17 01:58:26 EDT 1999


[Greg Ewing]
> ...
> The only way I can see that the 2-pass collection scheme
> can fail is if the finaliser of object A destroys something
> needed by the finaliser of object B. But if each object
> having a finaliser looks after just one external resource,
> how can that happen?

Greg, this is kind of like asking "if each loop terminates, how can we have
an infinite loop?".  That is, sure, if you write code that works, it works
<wink>.

> Anyone have a real-world example?

Not in *my* Python code <0.5 wink>.  It's all too tricky for me.  Doesn't
mean bigger minds than mine should be dissuaded, though.

Note that the Boehm-Demers-Weiser collector has most often been suggested
for Python (heck, it's a FAQ), and you may want to read about why *they*
guarantee that if A points to B, and both are registered for finalization,
A's finalizer gets called first; e.g., at

    http://reality.sgi.com/boehm_mti/finalization.html

This is an expensive and inconvenient decision for them to have made, so you
can be sure they didn't take it lightly.

BTW, a little-known characteristic of BDW is that given a cycle containing
finalizers, they let the cycle leak rather than risk running finalizers in a
wrong order.

when-the-reactor-is-going-critical-you-don't-want-to-lock-the-doors-
    before-the-people-get-out<wink>-ly y'rs  - tim






More information about the Python-list mailing list