smach.concurrence module
- class smach.concurrence.Concurrence(outcomes, default_outcome, input_keys=[], output_keys=[], outcome_map={}, outcome_cb=None, child_termination_cb=None)
Bases:
Container
Concurrence Container
This state allows for simple split-join concurrency. The user adds a set of states which are all executed simultaneously. The concurrent split state can only transition once all conatained states are ready to transition.
This container can be configured to return a given outcome as a function of the outcomes of the contained states. This is specified in the constructor of the class, or after construction with L{Concurrence.add_outcome_map}.
While a concurrence will not terminate until all if its children terminate, it is possible for it to preempt a subset of states
All child states terminate
At least one child state terminates
A user-defined callback signals termination
- Given these causes of termination, the outcome can be determined in four ways:
A user-defined callback returns an outcome
A child-outcome map which requires ALL states to terminate is satisfied
A child-outcome map which requires ONE state to terminate is satisfied
No maps are satisfied, so the default outcome is returned
The specification of the outcome maps and the outcome callback are described in the constructor documentation below. More than one policy can be supplied, and each policy has the potential to not be satisfied. In the situation in which multiple policies are provided, and a given policy is not satisfied, the outcome choice precedence is as follows:
Outcome callback
First-triggered outcome map
last-triggered outcome map
Default outcome
In practive it is best to try to accomplish your task with just ONE outcome policy.
- static add(label, state, remapping={})
Add state to the opened concurrence. This state will need to terminate before the concurrence terminates.
- check_consistency()
Check consistency of this container.
- execute(parent_ud=None)
Overridden execute method. This starts all the threads.
- get_active_states()
Get a description of the current states. Note that this is specific to container implementation.
@rtype: list of string
- get_children()
Get the children of this container. This is empty for leaf states.
@rtype: dict of string: State @return: The sub-states of this container.
- get_initial_states()
Get the initial states description.
@rtype: list of string
- get_internal_edges()
Get the internal outcome edges of this container. Get a list of 3-tuples (OUTCOME, LABEL_FROM, LABEL_TO) which correspond to transitions inside this container.
@rtype: list of 3-tuple
- request_preempt()
Preempt all contained states.
- set_initial_state(initial_states, userdata)
Set initial active states of a container.
@type initial_states: list of string @param initial_states: A description of the initial active state of this container.
@type userdata: L{UserData} @param userdata: Initial userdata for this container.