[Python-ideas] weakref.WeakKeyDictionary is (basically) useless
nykevin.norris at gmail.com
Wed Dec 31 19:26:44 CET 2014
On Wed, Dec 31, 2014 at 6:00 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> Why would you use it? The official documentation mentions
>> implementing a [descriptor]. See [this paste] for a simple
>> example of this sort of thing.
> How about something like this (untested):
A cursory glance suggests that might work for my use-case, but I would
want to examine it more thoroughly for race conditions and other
hazards. In particular, I'd be concerned about the potential
performance cost of removing things immediately on finalization (the
stdlib implementation uses a semi-lazy approach here, which I still
don't entirely understand). I'm also a little nervous about doing
anything remotely interesting from a finalizer.
With a little fine-tuning, however, this could be pulled into a
separate WeakKeyIDDictionary implementation, which would be more
modular and easier to work with.
More information about the Python-ideas