[pypy-dev] [cpyext] how to make use of the weakref callback?

Stefan Behnel stefan_ml at behnel.de
Sun Oct 14 19:59:33 CEST 2012


Hi,

when creating a new weakref using PyWeakref_NewRef(obj, callback), a Python
callback function can be registered that is supposed to get called when the
weakly referenced object dies. The callback receives a single argument, the
weakref object.

Now, the weak reference object itself is mostly useless, what is
interesting is the object it originally referenced. I tried getting at that
object by calling PyWeakref_LockObject(), but that already returns None at
that point. PyWeakref_GetObject() is basically just a wrapper around that
function and behaves the same.

Is there any way to figure out what that object was that has just died when
the callback gets called?

Stefan



More information about the pypy-dev mailing list