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

Merge branch 'L2SS-666-fix-clear-poll-cache' into 'master'

L2SS-666: Fix clear poll cache

Closes L2SS-666

See merge request !270
parents 069a81d4 c129e52a
No related branches found
No related tags found
1 merge request!270L2SS-666: Fix clear poll cache
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# PyTango imports # PyTango imports
from tango.server import attribute, command, Device, DeviceMeta 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 time
import math import math
import numpy import numpy
...@@ -83,26 +83,6 @@ class lofar_device(Device, metaclass=DeviceMeta): ...@@ -83,26 +83,6 @@ class lofar_device(Device, metaclass=DeviceMeta):
return self.get_state() in [DevState.STANDBY, DevState.ON, DevState.ALARM] 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() @log_exceptions()
def init_device(self): def init_device(self):
""" Instantiates the device in the OFF state. """ """ Instantiates the device in the OFF state. """
...@@ -123,6 +103,7 @@ class lofar_device(Device, metaclass=DeviceMeta): ...@@ -123,6 +103,7 @@ class lofar_device(Device, metaclass=DeviceMeta):
# we cannot write directly to our attribute, as that would not # 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 # 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 = DeviceProxy(self.get_name())
self.proxy.set_source(DevSource.DEV)
@log_exceptions() @log_exceptions()
def delete_device(self): def delete_device(self):
...@@ -163,8 +144,14 @@ class lofar_device(Device, metaclass=DeviceMeta): ...@@ -163,8 +144,14 @@ class lofar_device(Device, metaclass=DeviceMeta):
self.configure_for_initialise() self.configure_for_initialise()
# any values read so far are stale. clear the polling cache. # WARNING: any values read so far are stale.
self.clear_poll_cache() # 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_state(DevState.STANDBY)
self.set_status("Device is in the STANDBY state.") 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