Skip to content

Problem with write_attribute_asynch()

It seems that write_attribute_asynch() does not perform what expected. It takes very long time. No such a problem with read_attribute_asynch().

I have 124 attributes (coming from 124 different devices) to access, here are typical timings i get. None of the attributes are polled.

  • Synchronous and serialized writings of the 124 attributes is around ~52msec
  • Synchronous and serialized readings of the 124 attributes is around ~27msec

Here is what is produced by the code bellow:

read_attribute_asynch() 124 attributes: 0.002537965774536133 sec
read_attribute_reply() 124 attributes: 0.002348661422729492 sec
write_attribute_asynch() 124 attributes: 0.032013654708862305 sec
write_attribute_reply() 124 attributes: 0.0012378692626953125 sec
    def set(self, value: npt.NDArray[np.float64]):
        t0 = time.time()
        if len(value)!=len(self):
            raise pyaml.PyAMLException(f"Size of value ({len(value)} do not match the number of managed devices ({len(self)})")
        asynch_call_ids = []
        # Set part
        for index, device in enumerate(self):
            asynch_call_id = device._attribute_dev.write_attribute_asynch(device._attr_name, value[index])
            asynch_call_ids.append(asynch_call_id)
        t1 = time.time()
        print(f"write_attribute_asynch() {len(self)} attributes: {t1-t0} sec")

        # Wait part
        t0 = time.time()
        for index, call_id in enumerate(asynch_call_ids):
            self[index]._attribute_dev.write_attribute_reply(call_id)
        t1 = time.time()
        print(f"write_attribute_reply() {len(self)} attributes: {t1-t0} sec")

    def get(self) -> npt.NDArray[np.float64]:
        t0 = time.time()
        values = []
        asynch_call_ids = []
        # Read asynch
        for index, device in enumerate(self):
            asynch_call_id = device._attribute_dev.read_attribute_asynch(device._attr_name)
            asynch_call_ids.append(asynch_call_id)
        t1 = time.time()
        print(f"read_attribute_asynch() {len(self)} attributes: {t1-t0} sec")

        t0 = time.time()
        # Wait to read the set_point, ie the write part in a tango attribute.
        for index, call_id in enumerate(asynch_call_ids):
            dev_attr = self[index]._attribute_dev.read_attribute_reply(call_id)
            values.append(dev_attr.w_value)
        t1 = time.time()
        print(f"read_attribute_reply() {len(self)} attributes: {t1-t0} sec")

        return np.array(values)

Install:

cpptango                  10.0.2               h096aebb_3    conda-forge
pytango                   10.0.3          np22py312h0ed676d_0    conda-forge
Edited by Jean-Luc PONS