Module runner

class sismic.runner.AsyncRunner(interpreter, interval=0.1, execute_all=False)

Bases: object

An asynchronous runner that repeatedly execute given interpreter.

The runner tries to call its execute method every interval seconds, assuming that a call to that method takes less time than interval. If not, subsequent call is queued and will occur as soon as possible with no delay. The runner stops as soon as the underlying interpreter reaches a final configuration.

The execution must be started with the start method, and can be (definitively) stopped with the stop method. An execution can be temporarily suspended using the pause and unpause methods. A call to wait blocks until the statechart reaches a final configuration.

The current state of a runner can be obtained using its running and paused properties.

While this runner can be used “as is”, it is designed to be subclassed and as such, proposes several hooks to control the execution and additional behaviours:

  • before_run: called (only once !) when the runner is started.
  • after_run: called (only once !) when the interpreter reaches a final configuration. configuration of the underlying interpreter is reached.
  • execute: called at each step of the run. By default, call the execute_once method of the underlying interpreter and returns a list of macro steps.
  • before_execute: called right before the call to execute();
  • after_execute: called right after the call to execute(). This method is called with the returned value of execute().
Parameters:
  • interpreter (Interpreter) – interpreter instance to run.
  • interval (float) – interval between two calls to execute
  • execute_all – If set, repeatedly call interpreter’s execute_once method.
after_execute(steps)

Called after each call to self.execute(). Receives the return value of self.execute().

Parameters:steps (List[MacroStep]) – List of macrosteps returned by self.execute()
after_run()

Called after a final configuration is reached.

before_execute()

Called before each call to execute().

before_run()

Called before running the execution.

execute()

Called each time the interpreter has to be executed.

Return type:List[MacroStep]
pause()

Pause the execution.

paused

Holds if execution is running but paused.

running

Holds if execution is currently running (even if it’s paused).

start()

Start the execution.

stop()

Stop the execution.

unpause()

Unpause the execution.

wait()

Wait for the execution to finish.