[MERGE] Extend -Dhpss to emit a count of HPSS calls to stderr

Andrew Bennetts andrew at canonical.com
Fri Sep 26 03:17:16 BST 2008


John Arbash Meinel wrote:
> Robert Collins wrote:
[...]
> > I thought there was a weakref dict supplied by python that will
> > JustWork ?
> > 
> > -Rob
> 
> I think the problem is you need to know when the object goes away, and I
> don't think a weakref dict gives you that. (I could be wrong.)
> 
> But I'm guessing if you did:
> 
> counts = WeakValueDictionary()
> 
> counts[medium] = 0
> 
> when you're done, the value has disappeared, so you can't get to
> count[old_medium] == 10.

Yes, that's the problem exactly.  Although I'd want a WeakKeyDictionary,
not WeakValueDictionary.

It turns out that you can add your own weakref after adding to the
WeakKeyDictionary, and then your own weakref's callback can grab the
value out of the WeakKeyDictionary before it goes away...

This is safe (weakref callbacks are run in a guaranteed order), but
pretty subtle.  I've decided to use this anyway... patch to come.

-Andrew.




More information about the bazaar mailing list