Commit 5e3c7bfe by rfkelly0

more robust closing in ConnectionManagerFS

parent 510da574
...@@ -191,32 +191,16 @@ class ConnectionManagerFS(WrapFS): ...@@ -191,32 +191,16 @@ class ConnectionManagerFS(WrapFS):
poll_interval = 1 poll_interval = 1
def __init__(self,fs,poll_interval=None,connected=True): def __init__(self,wrapped_fs,poll_interval=None,connected=True):
super(ConnectionManagerFS,self).__init__(wrapped_fs)
if poll_interval is not None: if poll_interval is not None:
self.poll_interval = poll_interval self.poll_interval = poll_interval
if isinstance(fs,FS):
self.__dict__["wrapped_fs"] = fs
elif isinstance(fs,type):
self._fsclass = fs
self._fsargs = []
self._fskwds = {}
else:
self._fsclass = fs[0]
try:
self._fsargs = fs[1]
except IndexError:
self._fsargs = []
try:
self._fskwds = fs[2]
except IndexError:
self._fskwds = {}
self._connection_cond = threading.Condition() self._connection_cond = threading.Condition()
self._poll_thread = None self._poll_thread = None
self._poll_sleeper = threading.Event() self._poll_sleeper = threading.Event()
self.connected = connected self.connected = connected
@property def _get_wrapped_fs(self):
def wrapped_fs(self):
try: try:
return self.__dict__["wrapped_fs"] return self.__dict__["wrapped_fs"]
except KeyError: except KeyError:
...@@ -231,6 +215,26 @@ class ConnectionManagerFS(WrapFS): ...@@ -231,6 +215,26 @@ class ConnectionManagerFS(WrapFS):
finally: finally:
self._connection_cond.release() self._connection_cond.release()
def _set_wrapped_fs(self,fs):
if isinstance(fs,FS):
self.__dict__["wrapped_fs"] = fs
elif isinstance(fs,type):
self._fsclass = fs
self._fsargs = []
self._fskwds = {}
else:
self._fsclass = fs[0]
try:
self._fsargs = fs[1]
except IndexError:
self._fsargs = []
try:
self._fskwds = fs[2]
except IndexError:
self._fskwds = {}
wrapped_fs = property(_get_wrapped_fs,_set_wrapped_fs)
def setcontents(self,path,data): def setcontents(self,path,data):
self.wrapped_fs.setcontents(path,data) self.wrapped_fs.setcontents(path,data)
...@@ -278,15 +282,10 @@ class ConnectionManagerFS(WrapFS): ...@@ -278,15 +282,10 @@ class ConnectionManagerFS(WrapFS):
self._connection_cond.release() self._connection_cond.release()
def close(self): def close(self):
# Don't close if we haven't created it if not self.closed:
try:
fs = self.__dict__["wrapped_fs"]
except KeyError:
pass
else:
try: try:
fs.close() super(ConnectionManagerFS,self).close()
except (RemoteConnectionError,AttributeError): except (RemoteConnectionError,):
pass pass
if self._poll_thread: if self._poll_thread:
self.connected = True self.connected = True
......
...@@ -229,7 +229,9 @@ class WrapFS(FS): ...@@ -229,7 +229,9 @@ class WrapFS(FS):
@rewrite_errors @rewrite_errors
def close(self): def close(self):
self.wrapped_fs.close() if not self.closed:
self.wrapped_fs.close()
super(WrapFS,self).close()
def wrap_fs_methods(decorator,cls=None,exclude=[]): def wrap_fs_methods(decorator,cls=None,exclude=[]):
"""Apply the given decorator to all FS methods on the given class. """Apply the given decorator to all FS methods on the given class.
......
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