|
@@ -25,6 +25,8 @@ __all__ = ['LRUCache', 'is_list', 'maybe_list', 'memoize', 'mlazy', 'noop',
|
|
|
'first', 'firstmethod', 'chunks', 'padlist', 'mattrgetter', 'uniq',
|
|
|
'regen', 'dictfilter', 'lazy', 'maybe_evaluate', 'head_from_fun']
|
|
|
|
|
|
+IS_PYPY = hasattr(sys, 'pypy_version_info')
|
|
|
+
|
|
|
KEYWORD_MARK = object()
|
|
|
|
|
|
FUNHEAD_TEMPLATE = """
|
|
@@ -33,6 +35,15 @@ def {fun_name}({fun_args}):
|
|
|
"""
|
|
|
|
|
|
|
|
|
+class DummyContext(object):
|
|
|
+
|
|
|
+ def __enter__(self):
|
|
|
+ return self
|
|
|
+
|
|
|
+ def __exit__(self, *exc_info):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
class LRUCache(UserDict):
|
|
|
"""LRU Cache implementation using a doubly linked list to track access.
|
|
|
|
|
@@ -81,12 +92,15 @@ class LRUCache(UserDict):
|
|
|
pass
|
|
|
iteritems = _iterate_items
|
|
|
|
|
|
- def _iterate_values(self):
|
|
|
- for k in self:
|
|
|
- try:
|
|
|
- yield self.data[k]
|
|
|
- except KeyError: # pragma: no cover
|
|
|
- pass
|
|
|
+ def _iterate_values(self, _need_lock=IS_PYPY):
|
|
|
+ ctx = self.mutex if _need_lock else DummyContext()
|
|
|
+ with ctx:
|
|
|
+ for k in self:
|
|
|
+ try:
|
|
|
+ yield self.data[k]
|
|
|
+ except KeyError: # pragma: no cover
|
|
|
+ pass
|
|
|
+
|
|
|
itervalues = _iterate_values
|
|
|
|
|
|
def _iterate_keys(self):
|