hbp_nrp_excontrol.StateMachineInstance module

This module contains the class which encapsulates the dynamically loaded smach state machines

and provides the routines for their execution in parallel.

class StateMachineInstance(sm_id, sim_id, sim_dir, cle_error_pub=None, source_path=None)[source]

Bases: object

The class that encapsulates experiment controlling state machines and manages their execution in separate processes

initialize_sm()[source]

Loads the specified script file and initializes the encapsulated state machine.

property is_running

Gets for the encapsulated state machine whether its process is running or not

Returns

True if the state machine process is running, False otherwise.

property is_started

Gets a value indicating whether the state machine has been started

poll()[source]

Queries the return code of the current state machine process

request_termination()[source]

Requests termination of the encapsulated state machine. As the termination happens asynchronously this method will return immediately after setting the request flag. If the state machine has already finished execution the method simply returns.

restart()[source]

Restarts the state machine

property result

Gets the result of the state machine

shutdown()[source]

Shuts down this state machine

property sm_id

Gets the unique state machine identifier specified upon creation.

Returns

The unique state machine identifier.

property sm_path

Gets or sets the path to the state machine code

start_execution(fail_if_started=True)[source]

Starts the execution of the state machine in a separate thread.

Parameters

fail_if_started – If True, the state machines raises an Exception in case the state machine was started previously

wait_termination(timeout=0.2)[source]

Blocks until the encapsulated state machine has finished execution and a result is available

This will wait until the state machine process has terminated or the timeout has passed. If the timeout passed without the state machine process to terminate, a SIGINT is passed to the process and we wait again. If this does not help, a SIGTERM is sent and we wait again. Finally, we send a SIGKILL and wait for the process to complete.

Parameters

timeout – Maximum waiting time in seconds

create_state_machine(sm_id, path)[source]

Creates a state machine instance descriptor for the given state machine

Parameters
  • sm_id – The id of the state machine

  • path – The path to the state machine source code

Returns

A state machine descriptor