diff --git a/tangostationcontrol/tangostationcontrol/devices/lofar_device.py b/tangostationcontrol/tangostationcontrol/devices/lofar_device.py index 6943f86d4bde44010662cbcea45cb350ca271cea..067f09538d4cb972c0b1a186e726792b69132fbd 100644 --- a/tangostationcontrol/tangostationcontrol/devices/lofar_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/lofar_device.py @@ -13,7 +13,7 @@ # PyTango imports from tango.server import attribute, command, Device, DeviceMeta -from tango import AttrWriteType, DevState, DebugIt, Attribute, DeviceProxy, AttrDataFormat +from tango import AttrWriteType, DevState, DebugIt, Attribute, DeviceProxy, AttrDataFormat, DevSource import time import math import numpy @@ -83,26 +83,6 @@ class lofar_device(Device, metaclass=DeviceMeta): return self.get_state() in [DevState.STANDBY, DevState.ON, DevState.ALARM] - def clear_poll_cache(self): - """ Remove all attributes from the poll cache, to remove stale entries - once we know the values can be read. """ - - # we use proxy.attribute_query_list(), as proxy.get_attribute_list() will throw if we - # call it too soon when starting everything (database, device) from scratch. - attr_names = [config.name for config in self.proxy.attribute_list_query()] - - for attr_name in attr_names: - if self.proxy.is_attribute_polled(attr_name): - # save poll period - poll_period = self.proxy.get_attribute_poll_period(attr_name) - - try: - # stop polling to remove cache entry - self.proxy.stop_poll_attribute(attr_name) - finally: - # start polling again - self.proxy.poll_attribute(attr_name, poll_period) - @log_exceptions() def init_device(self): """ Instantiates the device in the OFF state. """ @@ -123,6 +103,7 @@ class lofar_device(Device, metaclass=DeviceMeta): # we cannot write directly to our attribute, as that would not # trigger a write_{name} call. See https://www.tango-controls.org/community/forum/c/development/c/accessing-own-deviceproxy-class/?page=1#post-2021 self.proxy = DeviceProxy(self.get_name()) + self.proxy.set_source(DevSource.DEV) @log_exceptions() def delete_device(self): @@ -163,8 +144,14 @@ class lofar_device(Device, metaclass=DeviceMeta): self.configure_for_initialise() - # any values read so far are stale. clear the polling cache. - self.clear_poll_cache() + # WARNING: any values read so far are stale. + # Proxies either need to wait for the next poll round, or + # use proxy.set_source(DevSource.DEV) to avoid the cache + # alltogether. + # + # Actually clearing the polling cache runs into performance + # problems if a lot of attributes are polled, and into race + # conditions with the polling thread itself. self.set_state(DevState.STANDBY) self.set_status("Device is in the STANDBY state.")