Re: [Python-ideas] weakref.WeakKeyDictionary is (basically) useless

On Wed, Dec 31, 2014 at 6:00 AM, Antoine Pitrou <solipsis@pitrou.net> wrote:
Why would you use it? The official documentation mentions implementing a [descriptor][1]. See [this paste][2] 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. -- Kevin Norris
participants (1)
-
Kevin Norris