Преглед на файлове

Attempt to fix pypy tests

Ask Solem преди 10 години
родител
ревизия
663486b213
променени са 1 файла, в които са добавени 20 реда и са изтрити 6 реда
  1. 20 6
      celery/utils/functional.py

+ 20 - 6
celery/utils/functional.py

@@ -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):