Commit 34278cc9 by rfkelly0

basic support for pickling FS instances

parent 19c56179
...@@ -221,6 +221,27 @@ class FS(object): ...@@ -221,6 +221,27 @@ class FS(object):
else: else:
self._lock = dummy_threading.RLock() self._lock = dummy_threading.RLock()
def __getstate__(self):
state = self.__dict__.copy()
lock = state.get("_lock",None)
if lock is not None:
if isinstance(lock,threading._RLock):
state["_lock"] = True
else:
state["_lock"] = False
return state
def __setstate__(self,state):
for (k,v) in state.iteritems():
print (k,v)
self.__dict__[k] = v
lock = state.get("_lock",None)
if lock is not None:
if lock:
self._lock = threading.RLock()
else:
self._lock = dummy_threading.RLock()
def _resolve(self, pathname): def _resolve(self, pathname):
resolved_path = resolvepath(pathname) resolved_path = resolvepath(pathname)
return resolved_path return resolved_path
......
...@@ -33,7 +33,7 @@ class TempFS(OSFS): ...@@ -33,7 +33,7 @@ class TempFS(OSFS):
This will be called automatically when the object is cleaned up by Python. This will be called automatically when the object is cleaned up by Python.
Note that once this method has been called, the FS object may no longer be used.""" Note that once this method has been called, the FS object may no longer be used."""
if not self._cleaned: if not self._cleaned and self.exists("/"):
self._lock.acquire() self._lock.acquire()
try: try:
rmtree(self._temp_dir) rmtree(self._temp_dir)
...@@ -47,4 +47,4 @@ class TempFS(OSFS): ...@@ -47,4 +47,4 @@ class TempFS(OSFS):
if __name__ == "__main__": if __name__ == "__main__":
tfs = TempFS() tfs = TempFS()
print tfs print tfs
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment