Commit 3f44ba74 by rfkelly0

DisconnectingFS: don't leave background thread running if constructor fails

parent 772ec802
...@@ -54,11 +54,12 @@ class DisconnectingFS(WrapFS): ...@@ -54,11 +54,12 @@ class DisconnectingFS(WrapFS):
fs = TempFS() fs = TempFS()
self._connected = True self._connected = True
self._continue = True self._continue = True
self._bounce_thread = threading.Thread(target=self._bounce) self._bounce_thread = None
self._bounce_thread.start()
super(DisconnectingFS,self).__init__(fs) super(DisconnectingFS,self).__init__(fs)
if random.choice([True,False]): if random.choice([True,False]):
raise RemoteConnectionError("") raise RemoteConnectionError("")
self._bounce_thread = threading.Thread(target=self._bounce)
self._bounce_thread.start()
def __getstate__(self): def __getstate__(self):
state = super(DisconnectingFS,self).__getstate__() state = super(DisconnectingFS,self).__getstate__()
...@@ -78,6 +79,7 @@ class DisconnectingFS(WrapFS): ...@@ -78,6 +79,7 @@ class DisconnectingFS(WrapFS):
def close(self): def close(self):
if not self.closed: if not self.closed:
self._continue = False self._continue = False
if self._bounce_thread is not None:
self._bounce_thread.join() self._bounce_thread.join()
self._connected = True self._connected = True
super(DisconnectingFS,self).close() super(DisconnectingFS,self).close()
......
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