How to protect attribute write value with critical section?

Hi Tango dancers!

In Sardana project we just tracked the source of a very annoying bug that moves motors to a wrong positions (usually 0)

What we basically do is that in the server we have a single worker thread responsible for pushing all change events. Before pushing an event the worker thread updates the attribute write value using the set_write_value() method.

This collides with processing the attribute write request since the write value obtained with get_write_value() returns corrupted data (usually at least one zero in case of the spectrum attribute).

I imagine that only the call to push_change_event() and processing the attribute write request are protected by the Serialization Monitor, so the arbitrary calls to set_write_value() are not protected.

I tried to use my own lock but without success. Do you have any suggestion on how to deal with that?

My colleague Miquel Navarro created this reduced example to reproduce this issue: https://github.com/Guspyro/tango-attributes-random-zero.

Many thanks in advance for your help!
Zibi
Hi Zibi,

I think you could use the AutoTangoMonitor class.
I didn't find any documentation for this class but it seems to be exposed in pyTango.

The following seems to work for me:


def backgroundWrite(self):
sleep(1.0) # Let the device server initialize correctly
while self.runBackgroundWrite:
with AutoTangoMonitor(self):
self.get_device_attr().get_attr_by_name('Position').set_write_value([1.2, 3.4])
self.debug_stream("Set_write_value [1.2, 3.4]")
sleep(0.001)
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.
Edited 1 day ago
For convenience, I created the following PR in the GIT repository you mentioned.

You can see the proposed patch here:

https://github.com/Guspyro/tango-attributes-random-zero/pull/1/files
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!
 
Register or login to create to post a reply.