diff --git a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/lofar_device.py b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/lofar_device.py index c0e267eef2aa5fb26fcb68940b9d9b861c7b99f8..4d3d1e8124c6cff8d0632777c7a6011232ede248 100644 --- a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/lofar_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/lofar_device.py @@ -16,7 +16,7 @@ from pathlib import Path from typing import List, Dict, Tuple from functools import partial -from inspect import iscoroutinefunction +from inspect import isawaitable import numpy from attribute_wrapper.attribute_wrapper import AttributeWrapper @@ -784,10 +784,12 @@ class LOFARDevice(Device): func = self._read_attribute(attr_name) - if iscoroutinefunction(func): + if isawaitable(func): return asyncio.run(func()) else: - return func() + result = func() + + return asyncio.run(result) if isawaitable(result) else result async def async_read_attribute(self, attr_name): """Read the value of a certain attribute (directly from the hardware). @@ -797,10 +799,12 @@ class LOFARDevice(Device): func = self._read_attribute(attr_name) - if iscoroutinefunction(func): + if isawaitable(func): return await func() else: - return func() + result = func() + + return await result if isawaitable(result) else result def wait_attribute(self, attr_name, value, timeout=10, pollperiod=0.2): """Wait until the given attribute obtains the given value. diff --git a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/opcua_device.py b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/opcua_device.py index 30469301a513d710e8270a01df0b2f7a00864e3b..eb903b5c892b1152ecbe652c0fa3af7321e64b22 100644 --- a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/opcua_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/opcua_device.py @@ -173,7 +173,8 @@ class OPCUADevice(LOFARDevice): self.OPC_Time_Out, self.Fault, self.opcua_connection_status, - event_loop=self.event_loop_thread.event_loop, + # TODO(JDM): This results in a deadlock when polling attributes and mixing green/non-green functionality + # event_loop=self.event_loop_thread.event_loop, device=self, ) self.opcua_connection.node_path_prefix = self.OPC_Node_Path_Prefix