[Python-Dev] Re: weakref gc semantics

Neil Schemenauer nas at arctrix.com
Thu Nov 4 18:38:35 CET 2004


On Thu, Nov 04, 2004 at 12:25:32AM -0500, Tim Peters wrote:
> One I sketched last time, and is in the attached patch-callback.txt. 
> (Patches here just have gcmodule.c code changes, no corresponding
> changes to comments.)  The difference is that it invokes a callback on
> a weakref to trash iff the callback is reachable, instead of invoking
> a callback on a weakref to trash iff the weakref it's attached to is
> reachable.

I like this idea best.  I don't see why it should be hard to
explain.  Instead of saying:

    If you want the weakref callback to be invoked, ensure the
    WEAKREF outlives the referent.

we say:

    If you want the weakref callback to be invoked, ensure the
    CALLBACK outlives the referent.

I think there may be one small problem though.  Callbacks get passed
the weakref object.  Doesn't that break the rule that trash should
not be exposed to Python code while the collection is taking place?

  Neil


More information about the Python-Dev mailing list