stucchio/Python-LRU-cache

Calling __delete__ in cleanup() modifies dict while iterating

timbrownsf opened this issue · 1 comments

for k in self.__expire_times:
    if self.__expire_times[k] < t:
        self.__delete__(k)

Will give:

>>> x = {'a': 1, 'b': 2}
>>> for k in x:
...     if k == 'a':
...             del x['a']
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration

self.__expire_times is an OrderDict() not an ordinary dict.