Przeglądaj źródła

LRUCache is pickleable

Mher Movsisyan 12 lat temu
rodzic
commit
b1ba3c6b93
1 zmienionych plików z 9 dodań i 0 usunięć
  1. 9 0
      celery/utils/functional.py

+ 9 - 0
celery/utils/functional.py

@@ -88,6 +88,15 @@ class LRUCache(UserDict):
             self[key] = str(newval)
         return newval
 
+    def __getstate__(self):
+        d = dict(vars(self))
+        d.pop('mutex')
+        return d
+
+    def __setstate__(self, state):
+        self.__dict__ = state
+        self.mutex = threading.RLock()
+
 
 def is_list(l):
     """Returns true if object is list-like, but not a dict or string."""