From 75e31714b8140e56356ef976f6808f62bf182907 Mon Sep 17 00:00:00 2001 From: Enrico Faulhaber Date: Mon, 25 Jun 2018 15:04:30 +0200 Subject: [PATCH] secop/modules: make polling thread more robust Change-Id: I530088d56e31dc2d415cc1c79b1db9d446c0b391 Reviewed-on: https://forge.frm2.tum.de/review/18259 Reviewed-by: Enrico Faulhaber Tested-by: JenkinsCodeReview --- secop/modules.py | 15 ++++++++------- secop_mlz/entangle.py | 10 ++++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/secop/modules.py b/secop/modules.py index a989f7b..daf2c21 100644 --- a/secop/modules.py +++ b/secop/modules.py @@ -231,13 +231,14 @@ class Readable(Module): mkthread(self.__pollThread, started_callback) def __pollThread(self, started_callback): - try: - self.__pollThread_inner(started_callback) - except Exception as e: - self.log.exception(e) - self.status = (self.Status.ERROR, 'polling thread could not start') - started_callback(self) - print(formatExtendedStack()) + while True: + try: + self.__pollThread_inner(started_callback) + except Exception as e: + self.log.exception(e) + self.status = (self.Status.ERROR, 'polling thread could not start') + started_callback(self) + print(formatExtendedStack()) def __pollThread_inner(self, started_callback): """super simple and super stupid per-module polling thread""" diff --git a/secop_mlz/entangle.py b/secop_mlz/entangle.py index beebea5..5920b97 100644 --- a/secop_mlz/entangle.py +++ b/secop_mlz/entangle.py @@ -379,8 +379,8 @@ class AnalogInput(PyTangoDevice, Readable): The AnalogInput handles all devices only delivering an analogue value. """ - def late_init(self): - super(AnalogInput, self).late_init() + def late_init(self, started_callback): + super(AnalogInput, self).late_init(started_callback) # query unit from tango and update value property attrInfo = self._dev.attribute_query('value') # prefer configured unit if nothing is set on the Tango device, else @@ -459,8 +459,8 @@ class AnalogOutput(PyTangoDevice, Drivable): self._history = [] # will keep (timestamp, value) tuple self._timeout = None # keeps the time at which we will timeout, or None - def late_init(self): - super(AnalogOutput, self).late_init() + def late_init(self, started_callback): + super(AnalogOutput, self).late_init(started_callback) # query unit from tango and update value property attrInfo = self._dev.attribute_query('value') # prefer configured unit if nothing is set on the Tango device, else @@ -497,6 +497,8 @@ class AnalogOutput(PyTangoDevice, Drivable): hist = self._history[:] window_start = currenttime() - self.window hist_in_window = [v for (t, v) in hist if t >= window_start] + if not hist_in_window: + return False # no relevant history -> no knowledge max_in_hist = max(hist_in_window) min_in_hist = min(hist_in_window)