secop/modules: make polling thread more robust

Change-Id: I530088d56e31dc2d415cc1c79b1db9d446c0b391
Reviewed-on: https://forge.frm2.tum.de/review/18259
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
This commit is contained in:
Enrico Faulhaber 2018-06-25 15:04:30 +02:00
parent fb1939d5c8
commit 75e31714b8
2 changed files with 14 additions and 11 deletions

View File

@ -231,13 +231,14 @@ class Readable(Module):
mkthread(self.__pollThread, started_callback) mkthread(self.__pollThread, started_callback)
def __pollThread(self, started_callback): def __pollThread(self, started_callback):
try: while True:
self.__pollThread_inner(started_callback) try:
except Exception as e: self.__pollThread_inner(started_callback)
self.log.exception(e) except Exception as e:
self.status = (self.Status.ERROR, 'polling thread could not start') self.log.exception(e)
started_callback(self) self.status = (self.Status.ERROR, 'polling thread could not start')
print(formatExtendedStack()) started_callback(self)
print(formatExtendedStack())
def __pollThread_inner(self, started_callback): def __pollThread_inner(self, started_callback):
"""super simple and super stupid per-module polling thread""" """super simple and super stupid per-module polling thread"""

View File

@ -379,8 +379,8 @@ class AnalogInput(PyTangoDevice, Readable):
The AnalogInput handles all devices only delivering an analogue value. The AnalogInput handles all devices only delivering an analogue value.
""" """
def late_init(self): def late_init(self, started_callback):
super(AnalogInput, self).late_init() super(AnalogInput, self).late_init(started_callback)
# query unit from tango and update value property # query unit from tango and update value property
attrInfo = self._dev.attribute_query('value') attrInfo = self._dev.attribute_query('value')
# prefer configured unit if nothing is set on the Tango device, else # 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._history = [] # will keep (timestamp, value) tuple
self._timeout = None # keeps the time at which we will timeout, or None self._timeout = None # keeps the time at which we will timeout, or None
def late_init(self): def late_init(self, started_callback):
super(AnalogOutput, self).late_init() super(AnalogOutput, self).late_init(started_callback)
# query unit from tango and update value property # query unit from tango and update value property
attrInfo = self._dev.attribute_query('value') attrInfo = self._dev.attribute_query('value')
# prefer configured unit if nothing is set on the Tango device, else # prefer configured unit if nothing is set on the Tango device, else
@ -497,6 +497,8 @@ class AnalogOutput(PyTangoDevice, Drivable):
hist = self._history[:] hist = self._history[:]
window_start = currenttime() - self.window window_start = currenttime() - self.window
hist_in_window = [v for (t, v) in hist if t >= window_start] 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) max_in_hist = max(hist_in_window)
min_in_hist = min(hist_in_window) min_in_hist = min(hist_in_window)