Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
fix: do not reserve motion objects multiple times in macro
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
reszelaz committed May 6, 2021
1 parent 9595940 commit 339e051
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/sardana/taurus/core/tango/sardana/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -295,6 +302,7 @@ def init_by_names(self, names, moveable_srcs, allow_repeat, allow_unknown):

# list<Moveable>
self.moveable_list = moveable_list
self._moveable_full_name_list = [m.full_name for m in moveable_list]

# list<tuple(int moveable_index, int position_index)>
# the list index itself is the position index for this motion
Expand Down

0 comments on commit 339e051

Please sign in to comment.