Skip to content

Commit

Permalink
Propagate exceptions when moves are cancelled
Browse files Browse the repository at this point in the history
If a move is cancelled, we should propagate the exception, so
that any actions that are calling the move method will also
be cancelled. For example, if an autofocus action is cancelled
during a move, not propagating the exception will allow it
to continue making the next move after this one aborts,
rather than cancelling the whole autofocus operation.

If different behaviour is desired, it's best to achieve that by
adding exception handling to the calling Action.
  • Loading branch information
rwb27 committed Jan 4, 2024
1 parent 4716a2d commit c1c6c88
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/labthings_sangaboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ def move_relative(self, cancel: CancelHook, block_cancellation: bool=False, **kw
else:
while sb.query("moving?") == "true":
cancel.sleep(0.1)
except InvocationCancelledError:
except InvocationCancelledError as e:
# If the move has been cancelled, stop it but don't handle the exception.
# We need the exception to propagate in order to stop any calling tasks,
# and to mark the invocation as "cancelled" rather than stopped.
sb.query("stop")
raise e
finally:
self.moving=False
self.update_position()
Expand Down

0 comments on commit c1c6c88

Please sign in to comment.