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

L2SS-1650: Allow Tango threads during read/write

parent 95128caa
Branches
No related tags found
1 merge request!4L2SS-1650: Allow Tango threads during read/write
Pipeline #68888 failed
......@@ -4,8 +4,9 @@
import logging
from functools import reduce
from operator import mul
from contextlib import nullcontext
from tango import AttrWriteType, AttReqType
from tango import AttrWriteType, AttReqType, AutoTangoAllowThreads
from tango.server import attribute
from attribute_wrapper.attribute_io import AttributeIO
......@@ -26,6 +27,7 @@ class AttributeWrapper(attribute):
datatype=None,
dims=(1,),
access=AttrWriteType.READ,
allow_threads=True,
**kwargs,
):
"""
......@@ -41,6 +43,8 @@ class AttributeWrapper(attribute):
datatype: any numpy datatype
dims: dimensions of the attribute as a tuple, or (1,) for a scalar.
init_value: value
allow_threads: if True, release Tango device lock during I/O, allowing other Tango
threads to execute.
"""
# ensure the type is a numpy array.
......@@ -62,6 +66,8 @@ class AttributeWrapper(attribute):
self.datatype = datatype
self.io_context = AutoTangoAllowThreads if allow_threads else nullcontext
if dims == (1,):
# scalar
# Tango defines a scalar as having dimensions (1,0), see
......@@ -109,6 +115,7 @@ class AttributeWrapper(attribute):
try:
io = self.get_attribute_io(device)
with self.io_context(device):
return io.cached_write_function(value)
except Exception as e:
raise e.__class__(
......@@ -129,6 +136,7 @@ class AttributeWrapper(attribute):
try:
io = self.get_attribute_io(device)
with self.io_context(device):
return io.cached_read_function()
except Exception as e:
raise e.__class__(
......@@ -154,6 +162,7 @@ class AttributeWrapper(attribute):
try:
io = self.get_attribute_io(device)
with AutoTangoAllowThreads(device):
return io.read_function()
except Exception as e:
raise e.__class__(
......@@ -182,14 +191,15 @@ class AttributeWrapper(attribute):
**kwargs,
)
def get_attribute_io(self, device):
"""Returns the attribute I/O functions from device"""
def make_attribute_io(self, device: Device) -> AttributeIO:
"""Creates and returns a new AttributeIO object for a given device"""
try:
return device._attribute_wrapper_io[self]
except KeyError:
device._attribute_wrapper_io[self] = AttributeIO(device, self)
return device._attribute_wrapper_io[self]
return AttributeIO(device, self)
def get_attribute_io(self, device: Device) -> AttributeIO:
"""Returns the (cached) attribute I/O functions from device"""
return device._attribute_wrapper_io.setdefault(self, self.make_attribute_io(device))
def set_comm_client(self, device, client):
"""Takes communication client with 'get_mapping' function
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment