Why device attribute list is different during server initialization and at runtime?
|
|
---|---|
Hello all, I have a question regarding the device attribute list on the server side. I use a PyTango DS and only dynamic attributes (created with `dyn_attr()` of the DeviceClass). When I get the list of attributes (using `<Device_Impl>.get_device_attr()`) it is empty during server initialization but when called at runtime it returns attributes added to other devices of this class. Note that during the server initialization we also add attributes to the devices of this class. You can use this example DS to reproduce this issue by following these steps (do not follow the steps from the repository): In one console (here the lines starting from "remove device attribute: attr1" appears after executing the code in the second console)
In another python console (after starting the server:
You can find me on Slack to clarify any doubt about this question. Many thanks, Zibi |
|
|
---|---|
Hi Zibi, I found this in cpptango doxygen documentation for Tango::DeviceImpl::add_attribute method: Attributes are normally constructed in the DeviceClass::attribute_factory() method. Nevertheless, it is still possible to add a new attribute to a device with this method. Please, note that if you add an attribute to a device at device creation time, this attribute will be added to the device class attribute list. Therefore, all devices belonging to the same class created after this attribute addition will also have this attribute. If you don't like this behaviour, you should create only 1 device of your class per device server process. Hoping this helps a bit. Reynald
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new. |
|
|
---|---|
Thanks Reynald for so fast reply! You helped a lot! The clue is this part of the docs you pointed: Therefore, all devices belonging to the same class created after this attribute addition will also have this attribute. At least in case of PyTango, during the server initialization, first all the devices of a given class are created and then we call `add_attribute()` in the dyn_attr() method. In this case none of the devices will have attributes cause the device class did not have any attribute when the devices were being created. This changes if we create a device at runtime. Here the device class is already aware of the previously added attrbiutes. |