From 339e051811963c9a8b8cc43bfa3d0a4c9eb0b740 Mon Sep 17 00:00:00 2001 From: zreszela Date: Thu, 6 May 2021 12:42:15 +0200 Subject: [PATCH] fix: do not reserve motion objects multiple times in macro Calling `Macro.getMotion()` for the same moveables multiple times in a macro creates a new object at every call and reserves each of them. When such macro gets stopped, each of these `Motion` objects gets stopped and the same moveables gets stopped multiple times. Fix it by implementing equality check (`__eq__()`) in the `Motion` class what avoids reserving different `Motion` objects pointing to the same moveables multiple times. --- src/sardana/taurus/core/tango/sardana/motion.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sardana/taurus/core/tango/sardana/motion.py b/src/sardana/taurus/core/tango/sardana/motion.py index cc28ae9492..a8c645937b 100644 --- a/src/sardana/taurus/core/tango/sardana/motion.py +++ b/src/sardana/taurus/core/tango/sardana/motion.py @@ -259,6 +259,13 @@ def __init__(self, elements, moveable_srcs, allow_repeat=False, def __str__(self): return self.__class__.__name__ + "(" + str(self.names) + ")" + def __eq__(self, other): + if not hasattr(other, "_moveable_full_name_list"): + return False + else: + return set(self._moveable_full_name_list) \ + == set(other._moveable_full_name_list) + def init_by_movables(self, elements, moveable_srcs, allow_repeat, allow_unknown): # TODO: Optimize this. Dont call init_by_names. It its possible to do it # manually with some performance gain @@ -295,6 +302,7 @@ def init_by_names(self, names, moveable_srcs, allow_repeat, allow_unknown): # list self.moveable_list = moveable_list + self._moveable_full_name_list = [m.full_name for m in moveable_list] # list # the list index itself is the position index for this motion