浏览代码

LRUCache is pickleable

Mher Movsisyan 12 年之前
父节点
当前提交
b1ba3c6b93
共有 1 个文件被更改,包括 9 次插入0 次删除
  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."""