From a44f3fae50b950eec1c0a61a0e4ad78dad48a672 Mon Sep 17 00:00:00 2001 From: l_samenv Date: Tue, 11 Jun 2024 08:08:42 +0200 Subject: [PATCH] frappy.modulebase: fix missing update after error on parameter --- frappy/client/__init__.py | 7 ------- frappy/modulebase.py | 2 +- frappy/proxy.py | 22 +++++++++------------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/frappy/client/__init__.py b/frappy/client/__init__.py index 2742d22..fcdf320 100644 --- a/frappy/client/__init__.py +++ b/frappy/client/__init__.py @@ -260,7 +260,6 @@ class ProxyClient: cblist = self.callbacks[cbname].get(key, []) for cbfunc in list(cblist): try: - # print("CALLBACK", cbname, repr(key), *args) cbfunc(*args) except UnregisterCallback: cblist.remove(cbfunc) @@ -495,8 +494,6 @@ class SecopClient(ProxyClient): return if self.activate: self.log.info('try to reconnect to %s', self.uri) - if self._connthread: - print('WARN connthread is still there') self._connthread = mkthread(self._reconnect) else: self.log.warning('%s disconnected', self.uri) @@ -513,15 +510,11 @@ class SecopClient(ProxyClient): def _reconnect(self, connected_callback=None): while not self._shutdown.is_set(): try: - # print('_reconnect_connect') self.connect() - # print('_reconnect_success') if connected_callback: connected_callback() - # print('_reconnect_break') break except Exception as e: - # print('_reconnect_exc', e) txt = str(e).split('\n', 1)[0] if txt != self._last_error: self._last_error = txt diff --git a/frappy/modulebase.py b/frappy/modulebase.py index cb4cc9c..423249c 100644 --- a/frappy/modulebase.py +++ b/frappy/modulebase.py @@ -524,7 +524,7 @@ class Module(HasAccessibles): except Exception as e: err = e else: - changed = pobj.value != value + changed = pobj.value != value or pobj.readerror # store the value even in case of error pobj.value = value if err: diff --git a/frappy/proxy.py b/frappy/proxy.py index e8ccbfb..366d71d 100644 --- a/frappy/proxy.py +++ b/frappy/proxy.py @@ -31,9 +31,6 @@ from frappy.io import HasIO DISCONNECTED = Readable.Status.ERROR, 'disconnected' -ACTIVATING = Readable.Status.IDLE, 'activating' -CONNECTED = Readable.Status.IDLE, 'connected' -CONN_STATI = {DISCONNECTED, ACTIVATING, CONNECTED} class ProxyModule(HasIO, Module): @@ -41,6 +38,7 @@ class ProxyModule(HasIO, Module): status = Parameter('connection status', Readable.status.datatype) # add status even when not a Readable _consistency_check_done = False + _connection_status = None # status when not connected _secnode = None enablePoll = False @@ -51,6 +49,8 @@ class ProxyModule(HasIO, Module): def updateEvent(self, module, parameter, value, timestamp, readerror): if parameter not in self.parameters: return # ignore unknown parameters + if parameter == 'status' and not readerror: + self._connection_status = None # should be done here: deal with clock differences self.announceUpdate(parameter, value, readerror, timestamp) @@ -115,21 +115,17 @@ class ProxyModule(HasIO, Module): def nodeStateChange(self, online, state): if online: - if state == 'activating': - self.status = ACTIVATING - else: - if not self._consistency_check_done: - self._check_descriptive_data() - self._consistency_check_done = True - if self.status[0] in CONN_STATI: - # avoid overriding remote status - self.status = CONNECTED + if not self._consistency_check_done: + self._check_descriptive_data() + self._consistency_check_done = True + if self._connection_status: + self.status = Readable.Status.IDLE, state else: readerror = CommunicationFailedError('disconnected') if self.status != DISCONNECTED: for pname in set(self.parameters) - set(('module', 'status')): self.announceUpdate(pname, None, readerror) - self.status = DISCONNECTED + self.status = self._connection_status = DISCONNECTED def checkProperties(self): pass # skip