Make MemoryCache picklable.
authorJosh Roesslein <jroesslein@gmail.com>
Thu, 30 Jul 2009 19:03:09 +0000 (14:03 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Thu, 30 Jul 2009 19:03:09 +0000 (14:03 -0500)
tweepy/cache.py

index 1e1b37ece21d6c0c94cfaf4ecc33815ce001757e..9062f2284ec41a2a76266503e904a25058eeba5f 100644 (file)
@@ -44,6 +44,16 @@ class MemoryCache(Cache):
     self._entries = {}
     self.lock = threading.Lock()
 
+  def __getstate__(self):
+    # pickle
+    return {'entries': self._entries, 'timeout': self.timeout}
+
+  def __setstate__(self, state):
+    # unpickle
+    self.lock = threading.Lock()
+    self._entries = state['entries']
+    self.timeout = state['timeout']
+
   def _is_expired(self, entry, timeout):
     return timeout > 0 and (time.time() - entry[0]) >= timeout