yasmin.concurrence module

class yasmin.concurrence.Concurrence(states: List[State], default_outcome: str, outcome_map: Dict[str, Dict[State, str]] = {})

Bases: State

Child class of a State that runs multiple other states in parallel threads.

Attributes:

_states (List[State]): A list of states that will be run in parallel by this state. _outcome_map (Dict[str, Dict[int, str]]): A dictionary correlating the outcomes of the concurrent states to

outcomes of this state.

_default_outcome (str): A default outcome in case none of the correlations in _outcome_map are satisfied. _intermediate_outcomes (Dict[str, Optional[str]]): A temporary storage of the parallel states’s outcomes. _mutex (Lock): A mutex to ensure thread safety of _intermediate_outcomes.

cancel_state() None

Cancels the execution of all states.

execute(blackboard: Blackboard) str

Executes the parallel behavior.

Parameters:

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

Returns:

The outcome of the execution as a string.

execute_and_save_state(state: State, state_id: int, blackboard: Blackboard) None

Executes a state and saves its outcome to the intermediate map.

Parameters:
  • state – A state to execute.

  • state_id – The internal state ID associated with the state to execute.

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

Returns:

None