Skip to content
Snippets Groups Projects
Commit c129e52a authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-666: Replace clearing the poll cache by using a DevSource.DEV proxy for...

L2SS-666: Replace clearing the poll cache by using a DevSource.DEV proxy for all the proxies that need to supply hot values.
parent 46298110
Branches
No related tags found
Loading
......@@ -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.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment