`mv` context manager
(from discussion with @vimiche and previous discussions with @sebastien.petitdemange )
Proposal
Deprecate .move
and .wait_move
methods of Axis
objects for users, in favor of a new mv
function that would return a context manager. This context manager would guarantee motors are stopped in case of exception, or even returned to their initial position with a special keyword argument.
Note: move
and waitmove
features will still be used internally (existing methods renamed with _
?)
Problem to solve
This fixes the potential bugs with code like this:
m0.move(5, wait=False)
m1.move(3, wait=False)
... do something ...
m0.wait_move()
m1.wait_move()
In example above, if ctrl-c is issued in ... do something...
, motors would continue to move.
Example usage of the new proposal
with mv(m0, 5, m1, 3, wait=False) as grouped_move:
...
do something while m0, m1 are moving
...
# when execution reaches here, motor are not moving
... now do something else
If ctrl-c or any other exception happens in the mv
context, m0 and m1 will be stopped.
Example of a move_back_on_error
flag:
with mv(m0, 4, m1, 3, wait=False, move_back_on_error=True):
.... do something ...
# when execution reaches here, motors are not moving; if an error happened,
# motors have been moved back to their initial positions before 'mv'
wait() function
The mv
context manager can also have a .wait()
method, to wait on demand.