From 55431da1fe84489f50b4a411cbcff6325887217d Mon Sep 17 00:00:00 2001
From: Romain Broucquart <romain.broucquart@synchrotron-soleil.fr>
Date: Fri, 25 Sep 2020 15:48:17 +0200
Subject: [PATCH] [ContextSaver] Switch to batch attribute access

Do not loop access on tango devices, use group access.
---
 ContextSaver.py | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/ContextSaver.py b/ContextSaver.py
index 63c23fb..ca24584 100644
--- a/ContextSaver.py
+++ b/ContextSaver.py
@@ -31,27 +31,36 @@ def get_wattr(proxy):
     logger.debug("Scanning write attribute of device %s"%proxy.name())
     config = dict()
 
-    # Scan all attributes
-    for attr in proxy.get_attribute_list():
+    # Get all attributes configuration
+    cattr = proxy.get_attribute_config(proxy.get_attribute_list())
+    wattr=[]
+    for attr in cattr:
         logger.debug("Analyse attribute '%s' "%(
-                attr))
+                attr.name))
 
-        try:
-            if proxy.get_attribute_config(attr).writable in [
+        if attr.writable in [
                     tango.AttrWriteType.WRITE,
                     tango.AttrWriteType.READ_WRITE,
                     tango.AttrWriteType.READ_WITH_WRITE]:
-                v= proxy[attr].value
-                if type(v) is numpy.ndarray:
-                    v=v.tolist()
 
-                config[attr]=v
+            # attr is writtable, savbing it into list
+            wattr.append(attr.name)
 
-                logger.debug("Detect writtable attribute '%s' = %s"%(
-                    attr,
-                    proxy[attr].value))
-        except tango.DevFailed:
-            logger.warning("Failed to save attribute '%s'"%attr)
+            logger.debug("Detect writtable attribute '%s'"%(
+                attr.name))
+
+    # Read all writtable attributes
+    rattr = proxy.read_attributes(wattr)
+    for attr in rattr:
+        v= attr.value
+        if type(v) is numpy.ndarray:
+            v=v.tolist()
+
+        logger.debug("Read writtable attribute '%s' = %s"%(
+            attr.name,
+            v))
+
+        config[attr.name]=v
 
     return config
 
-- 
GitLab