[Python-Dev] weakref enhancements

Alex Martelli aleaxit at gmail.com
Thu Sep 28 23:14:13 CEST 2006

On 9/28/06, tomer filiba <tomerfiliba at gmail.com> wrote:
> > I'm sceptical that these would find use in practice.
> > [..]
> > Also, I question the utility of maintaining a weakref to a method or
> > attribute instead of holding one for the object or class.  As long as
> > the enclosing object or class lives, so too will their methods and
> > attributes.  So what is the point of a tighter weakref granualarity?
> i didn't just came up with them "out of boredom", i have had specific
> use cases for these, mainly in rpyc3000... but since the rpyc300
> code base is still far from completion, i don't want to give examples
> at this early stage.
> however, these two are theoretically useful, so i refactored them out
> of my code into recipes.

I've had use cases for "weakrefs to boundmethods" (and there IS a
Cookbook recipe for them), as follows: sometimes I'm maintaining a
container of callables, which may be of various kinds including
functions, boundmethods, etc; but I'd like the mere presence of a
callable in the container not to keep the callable alive (especially
when the callable in turn keeps alive an object with possibly massive
state). In practice I use wrapping and tricks, but it would be nice to
have cleaner standard library support for this. (Often the container
needs to be some form of a Queue.Queue, since queues of callables are
a form I use very often to dispatch work requests to worker-threads in
a threadpool).


More information about the Python-Dev mailing list