step.timeout

Classes

Timeout

Wrap a step with a time limit, cancelling it if it runs too long.

Module Contents

class step.timeout.Timeout(step: step.Step, seconds: float | int, propagate: bool = False)

Bases: step.Step

Wrap a step with a time limit, cancelling it if it runs too long.

Executes the given step normally but enforces a maximum wall-clock duration. If the wrapped step completes within the budget, the timeout step finishes successfully. If the step exceeds the time limit, it is cancelled via asyncio.wait_for and an error is logged.

By default (propagate=False) an expired timeout is contained: it cancels only the wrapped step and then finishes successfully, so the surrounding sequence and every remaining mission keep running. This is what you almost always want on a robot — one stuck motor_move_to should not take down the whole run.

Set propagate=True to instead re-raise TimeoutError after cancelling the wrapped step. That aborts the enclosing sequence/mission and is only appropriate when the wrapped step is a hard prerequisite for everything that follows.

Note that the wrapped step is always cancelled on timeout (its finally blocks run, so a MotionStep still hard-stops the motors); propagate only controls whether the timeout itself is treated as a failure of the enclosing mission. Any other exception raised by the wrapped step propagates normally regardless of propagate.

This is especially useful around blocking steps like motor_move_to or wait_for_button that could stall indefinitely if the hardware misbehaves.

Parameters:
  • step – The step to execute under a time constraint. Must be a valid Step (or StepProtocol) instance.

  • seconds – Maximum allowed execution time in seconds. Must be positive.

  • propagate – When False (default), a timeout cancels only the wrapped step and the mission continues. When True, the TimeoutError is re-raised after cancellation, aborting the enclosing sequence/mission.

Example:

from raccoon.step import timeout
from raccoon.step.motor import motor_move_to

# Give the arm 5 seconds to reach position 300; cancel if stuck,
# then carry on with the rest of the mission.
timeout(
    motor_move_to(robot.motor(2), position=300, velocity=800),
    seconds=5.0,
)

# Hard prerequisite: abort the mission if the button isn't pressed
timeout(wait_for_button(), seconds=30.0, propagate=True)
step
seconds
propagate = False
result = None
collected_resources() frozenset[str]