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:
zolliker 2024-05-02 09:02:04 +02:00
parent 798c268eb4
commit 647d87f70f

View File

@ -317,8 +317,11 @@ class SecopClient(ProxyClient):
self.register_callback(None, self.handleError)
def __del__(self):
# make sure threads are stopping. this is needed in case
# a frappy client object is lost without calling .disconnect()
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)
except Exception:
pass
@ -405,6 +408,7 @@ class SecopClient(ProxyClient):
def __rxthread(self):
noactivity = 0
shutdown = False
try:
while self._running:
while self.cleanup:
@ -480,14 +484,13 @@ class SecopClient(ProxyClient):
except ConnectionClosed:
pass
except Exception as e:
self._shutdown.set()
shutdown = True
self.callback(None, 'handleError', e)
finally:
self._rxthread = None
self.disconnect(shutdown)
if self._shutdown.is_set():
self.disconnect(True)
return
self.disconnect(False)
if self.activate:
self.log.info('try to reconnect to %s', self.uri)
self._connthread = mkthread(self._reconnect)