step.timeout_or¶
Classes¶
Run a step with a time limit; execute a fallback step if it times out. |
Functions¶
|
Run a step with a time limit, executing a fallback step if it times out. |
Module Contents¶
- class step.timeout_or.TimeoutOr(step: step.Step, seconds: float | int, fallback: step.Step)¶
Bases:
step.StepRun a step with a time limit; execute a fallback step if it times out.
- step¶
- seconds¶
- fallback¶
- step.timeout_or.timeout_or(step: step.Step, seconds: float | int, fallback: step.Step) TimeoutOr¶
Run a step with a time limit, executing a fallback step if it times out.
Executes
stepnormally and enforces a maximum wall-clock duration. If the step completes within the budget it finishes successfully and the fallback is never run. Ifstepexceeds the time limit it is cancelled andfallbackis executed in its place.This is useful when a motion step might stall (e.g., a drive that never reaches its target) and you want a recovery action rather than simply logging an error and moving on.
- Parameters:
step – The primary step to execute under a time constraint. Must be a valid
Stepinstance.seconds – Maximum allowed execution time in seconds. Must be positive.
fallback – The step to execute when
steptimes out.
- Returns:
A TimeoutOr step instance.
Example:
from raccoon.step import timeout_or from raccoon.step.motion import drive_forward, drive_backward # Try driving forward 30 cm; if stuck after 3 s, back up 5 cm instead timeout_or( drive_forward(30), seconds=3.0, fallback=drive_backward(5), )