frappy.client: avoid shutdown callback sent twice
in case th rx thread crashes, the shutdown callback is called twice -> improve cleanup code in __rxthread Change-Id: I0d20aa4304d94b17565b018ad8528d61bbbcbc83 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/33614 Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de> Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
parent
798c268eb4
commit
647d87f70f
@ -317,8 +317,11 @@ class SecopClient(ProxyClient):
|
|||||||
self.register_callback(None, self.handleError)
|
self.register_callback(None, self.handleError)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
# make sure threads are stopping. this is needed in case
|
||||||
|
# a frappy client object is lost without calling .disconnect()
|
||||||
try:
|
try:
|
||||||
self.callbacks.clear() # avoid callbacks when deleting. may cause deadlocks in NICOS
|
# avoid callbacks when deleting. may cause deadlocks in NICOS
|
||||||
|
self.callbacks.clear()
|
||||||
self.disconnect(True)
|
self.disconnect(True)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
@ -405,6 +408,7 @@ class SecopClient(ProxyClient):
|
|||||||
|
|
||||||
def __rxthread(self):
|
def __rxthread(self):
|
||||||
noactivity = 0
|
noactivity = 0
|
||||||
|
shutdown = False
|
||||||
try:
|
try:
|
||||||
while self._running:
|
while self._running:
|
||||||
while self.cleanup:
|
while self.cleanup:
|
||||||
@ -480,14 +484,13 @@ class SecopClient(ProxyClient):
|
|||||||
except ConnectionClosed:
|
except ConnectionClosed:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._shutdown.set()
|
shutdown = True
|
||||||
self.callback(None, 'handleError', e)
|
self.callback(None, 'handleError', e)
|
||||||
finally:
|
finally:
|
||||||
self._rxthread = None
|
self._rxthread = None
|
||||||
|
self.disconnect(shutdown)
|
||||||
if self._shutdown.is_set():
|
if self._shutdown.is_set():
|
||||||
self.disconnect(True)
|
|
||||||
return
|
return
|
||||||
self.disconnect(False)
|
|
||||||
if self.activate:
|
if self.activate:
|
||||||
self.log.info('try to reconnect to %s', self.uri)
|
self.log.info('try to reconnect to %s', self.uri)
|
||||||
self._connthread = mkthread(self._reconnect)
|
self._connthread = mkthread(self._reconnect)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user