[Python-Dev] Weak Dictionary Iteration Behavior in Python 3

Antoine Pitrou solipsis at pitrou.net
Sun Sep 14 15:48:05 CEST 2008


Nick Coghlan <ncoghlan <at> gmail.com> writes:
> 
> I agree this is a problem, but I'm struggling to think of possible
> solutions that aren't either horrendously complicated or completely
> contrary to the idea of view-based dicts.

Keeping a count of the number of views currently alive for a given weak dict
doesn't seem "horrendously complicated" (*). Once this count falls to zero, you
can purge all the dead weakrefs from the dict (their keys would have been
previously queued, so that purging is O(dead weakrefs) and not O(dict length)).

(*) the most complicated is probably to write the view classes themselves




More information about the Python-Dev mailing list