[Python-Dev] Weak Dictionary Iteration Behavior in Python 3
Armin Ronacher
armin.ronacher at active-4.com
Sun Sep 14 11:39:31 CEST 2008
Hi,
Adam Olsen <rhamph <at> gmail.com> writes:
> IMO, this is a deeper problem than suggested. As far as I know,
> python does not (and should not) make promises as to when it'll
> collect object. We should expect weakrefs to be cleared at random
> points, and code defensively.
It doesn't promise when objects are collected and that's not the problem
here. The main problem is that the old solution for weakrefs relayed on
the fact that .keys() was considered atomic. I don't say it has to
become again, but the weak dictionaries have to somehow counter that
problem. They could for example only remove items from the internal dict
if no dict view to that dict is alive.
Speaking of atom keys() / values() / items() operations: I guess we will
see more of those problems in threaded situations when people start to
convert code over to Python. I've seen quite a few situations where code
relays on keys() holding the interpreter lock.
Regards,
Armin
More information about the Python-Dev
mailing list