yasmin.state module

class yasmin.state.State(outcomes: Set[str])

Bases: ABC

Abstract base class representing a state in a state machine.

This class provides a framework for creating specific states with defined outcomes. Subclasses must implement the execute method to define the state-specific behavior.

Attributes:

_outcomes (Set[str]): A set of valid outcomes for this state. __status (StateStatus): Current status of the state. __status_lock (threading.Lock): Lock for thread-safe status operations.

cancel_state() None

Cancels the execution of the state.

Sets the status to CANCELED and logs the cancellation.

abstractmethod execute(blackboard: Blackboard) str

Executes the specific behavior of the state.

This method must be implemented by subclasses to define what happens when the state is executed.

Parameters:

blackboard – An instance of Blackboard that provides the context for execution.

Returns:

The outcome of the execution as a string.

Raises:

NotImplementedError – If not implemented in a subclass.

get_outcomes() Set[str]

Gets the valid outcomes for this state.

Returns:

A set of valid outcomes as strings.

get_status() StateStatus

Gets the current status of the state.

Returns:

The current StateStatus.

is_canceled() bool

Checks if the state has been canceled.

Returns:

True if the state is canceled, False otherwise.

is_completed() bool

Checks if the state has completed execution.

Returns:

True if the state is completed, False otherwise.

is_idle() bool

Checks if the state is idle.

Returns:

True if the state is idle, False otherwise.

is_running() bool

Checks if the state is currently running.

Returns:

True if the state is running, False otherwise.

set_status(status: StateStatus) None

Sets the current status of the state.

Parameters:

status – The StateStatus to set.

class yasmin.state.StateStatus(*values)

Bases: Enum

Enumeration representing the current status of a state.

CANCELED = 'canceled'
COMPLETED = 'completed'
IDLE = 'idle'
RUNNING = 'running'