Skip to content

Commit

Permalink
Use DeviceProxy instead of taurus in MacroServer
Browse files Browse the repository at this point in the history
Use DeviceProxy instead of taurus to avoid crashes in Py3
See: tango-controls/pytango#292

To be reverted when the above issue gets clarified
  • Loading branch information
reszelaz committed Jul 20, 2019
1 parent 3ca968c commit 2f0a36a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/sardana/macroserver/scan/gscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,10 @@ def _setupEnvironment(self, additional_env):
for ci in channels_info:
full_name = ci.full_name
try:
channel = taurus.Device(full_name)
# Use DeviceProxy instead of taurus to avoid crashes in Py3
# See: tango-controls/pytango#292
# channel = taurus.Device(full_name)
channel = PyTango.DeviceProxy(full_name)
instrument = channel.instrument
except Exception:
# full_name of external channels is the name of the attribute
Expand Down Expand Up @@ -2036,7 +2039,10 @@ def is_measurement_group_compatible(measurement_group):
full_name = channel_info["full_name"]
name = channel_info["name"]
try:
taurus.Device(full_name)
# Use DeviceProxy instead of taurus to avoid crashes in Py3
# See: tango-controls/pytango#292
# taurus.Device(full_name)
PyTango.DeviceProxy(full_name)
except Exception:
# external channels are attributes so Device constructor fails
non_compatible_channels.append(name)
Expand Down
44 changes: 32 additions & 12 deletions src/sardana/taurus/core/tango/sardana/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@
}


def _is_referable(channel):
# Equivalent to ExpChannel.isReferable.
# Use DeviceProxy instead of taurus to avoid crashes in Py3
# See: tango-controls/pytango#292
if isinstance(channel, str):
channel = DeviceProxy(channel)
return "valueref" in list(map(str.lower, channel.get_attribute_list()))


class InterruptException(Exception):
pass

Expand Down Expand Up @@ -1447,12 +1456,15 @@ def _build(self):
dev_data = tg_dev_chs.get(dev_name)
# technical debt: read Value or ValueRef attribute
# ideally the source configuration should include this info
channel = Device(dev_name)
if (isinstance(channel, ExpChannel)
and channel.isReferable()
# Use DeviceProxy instead of taurus to avoid crashes in Py3
# See: tango-controls/pytango#292
# channel = Device(dev_name)
# if (isinstance(channel, ExpChannel)
# and channel.isReferable()
# and channel_data.get("value_ref_enabled", False)):
if (_is_referable(dev_name)
and channel_data.get("value_ref_enabled", False)):
attr_name += "Ref"

if dev_data is None:
# Build tango device
dev = None
Expand Down Expand Up @@ -1898,9 +1910,11 @@ def subscribeValueBuffer(self, cb=None):
for channel_info in self.getChannels():
full_name = channel_info["full_name"]
value_ref_enabled = channel_info.get("value_ref_enabled", False)
channel = Device(full_name)
if channel.isReferable() and value_ref_enabled:
# Use DeviceProxy instead of taurus to avoid crashes in Py3
# See: tango-controls/pytango#292
if _is_referable(full_name) and value_ref_enabled:
continue
channel = Device(full_name)
value_buffer_obj = channel.getValueBufferObj()
if cb is not None:
self._value_buffer_cb = cb
Expand All @@ -1922,9 +1936,11 @@ def unsubscribeValueBuffer(self, cb=None):
for channel_info in self.getChannels():
full_name = channel_info["full_name"]
value_ref_enabled = channel_info.get("value_ref_enabled", False)
channel = Device(full_name)
if channel.isReferable() and value_ref_enabled:
# Use DeviceProxy instead of taurus to avoid crashes in Py3
# See: tango-controls/pytango#292
if _is_referable(full_name) and value_ref_enabled:
continue
channel = Device(full_name)
value_buffer_obj = channel.getValueBufferObj()
if cb is not None:
value_buffer_obj.unsubscribeEvent(self.valueBufferChanged,
Expand Down Expand Up @@ -1963,11 +1979,13 @@ def subscribeValueRefBuffer(self, cb=None):
for channel_info in self.getChannels():
full_name = channel_info["full_name"]
value_ref_enabled = channel_info.get("value_ref_enabled", False)
channel = Device(full_name)
if not channel.isReferable():
# Use DeviceProxy instead of taurus to avoid crashes in Py3
# See: tango-controls/pytango#292
if not _is_referable(full_name):
continue
if not value_ref_enabled:
continue
channel = Device(full_name)
value_ref_buffer_obj = channel.getValueRefBufferObj()
if cb is not None:
self._value_ref_buffer_cb = cb
Expand All @@ -1989,11 +2007,13 @@ def unsubscribeValueRefBuffer(self, cb=None):
for channel_info in self.getChannels():
full_name = channel_info["full_name"]
value_ref_enabled = channel_info.get("value_ref_enabled", False)
channel = Device(full_name)
if not channel.isReferable():
# Use DeviceProxy instead of taurus to avoid crashes in Py3
# See: tango-controls/pytango#292
if not _is_referable(full_name):
continue
if not value_ref_enabled:
continue
channel = Device(full_name)
value_ref_buffer_obj = channel.getValueRefBufferObj()
if cb is not None:
value_ref_buffer_obj.unsubscribeEvent(
Expand Down

0 comments on commit 2f0a36a

Please sign in to comment.