Can someone explain this weakref behavior?
Mike C. Fletcher
mcfletch at rogers.com
Mon Jun 14 11:55:20 EDT 2004
Michael Kent wrote:
>"Tim Peters" <tim.one at comcast.net> wrote in message news:<mailman.874.1086976586.6949.python-list at python.org>...
>
>
>
>>The bound methods you create become unreachable (via any strong reference)
>>the instant they're added to the weak dict, so they vanish from the weak
>>dict immediately after being added. That's what a weak dict is supposed to
>>do.
>>
>>
>
>OK, I think I understand where you're coming from. My
>misunderstanding was that a persistant reference to the object would
>keep the object alive, and thus was sufficient to keep a weak
>reference to a bound method of the object alive. But the two
>references are totally independent, right? So keeping the object
>alive isn't sufficient to keeping the weak reference to a bound method
>of the object alive.
>
>Back to the drawing board...
>
>
Or you could just take the "saferef" module from the Dispatcher project
(the poor naming is my fault):
http://pydispatcher.sourceforge.net/
http://cvs.sourceforge.net/viewcvs.py/pydispatcher/dispatch/saferef.py?view=markup
Which does the work of deconstructing the method reference into two
weak-references for you. Once you have that, keeping the object alive
is sufficient.
HTH,
Mike
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
blog: http://zope.vex.net/~mcfletch/plumbing/
More information about the Python-list
mailing list