pypz.executors.operator.states module

class pypz.executors.operator.states.State(context: ExecutionContext, *args, **kwargs)

Bases: ABC

This class is used to collect and abstract the common logic in all derived states. All other states must extend on this class.

Parameters:

contextpypz.executors.operator.context.ExecutionContext

class Execution(method: Any, instances: set[Instance], *args, **kwargs)

Bases: object

class MethodWrapper(state: State, instance_name: str, callable_method: Callable[[...], bool])

Bases: object

This class represents the invocation of the plugin objects’ method as action. It is used by both the parallel and the sequential executor.

Parameters:
  • state – the state object, where the execution is performed

  • instance_name – name of the executable instance

  • callable_method – the method of the instance to be invoked

__enter_state()
__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

__exit_state()
_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_schedule(*execution_chain: Execution, break_on_exception: bool = False) bool

Schedules a chain of instances’ specified methods for execution via the thread pool executor. Each chain element is represented by a list of instances and the method to be called. Each list will be executed parallel. The next chain element will be executed after all instance methods have been concluded on the current chain element. This method blocks until all the scheduled methods are finished. Both plugin and operator instance methods can be scheduled.

Parameters:
  • execution_chain – list of tuples, where [0] is the callable method and [1] is the list of instances

  • break_on_exception – if True, it will break on the first exception, if False, it will let then chain run and only raise an exception at the end

Returns:

True if all methods are finished (returned True), False otherwise

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

get_prev_state() State | None
get_transitions()
abstract on_entry() None
abstract on_execute() BaseSignal
abstract on_exit() None
on_signal_handling(signal: BaseSignal) State
set_transition(signal: Type[BaseSignal], new_state: State) None
shutdown()
class pypz.executors.operator.states.StateEntry(context: ExecutionContext, *args, **kwargs)

Bases: State

Serves as entry point for the state machine.

Parameters:

contextpypz.executors.operator.context.ExecutionContext

__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_logger: ContextLogger
_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

on_entry() None
on_execute() BaseSignal
on_exit() None
class pypz.executors.operator.states.StateKilled(context: ExecutionContext, *args, **kwargs)

Bases: State

Serves as exit point for the state machine.

Parameters:

contextpypz.executors.operator.context.ExecutionContext

__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_logger: ContextLogger
_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

on_entry() None
on_execute() BaseSignal
on_exit() None
class pypz.executors.operator.states.StateOperationInit(context: ExecutionContext, *args, **kwargs)

Bases: State

This state initializes the operator.

Invoked methods:

  1. pypz.core.specs.plugin.PortPlugin._on_port_open()

  2. pypz.core.specs.operator.Operator._on_init()

This order of execution guarantees that the Operator’s implementation is already having access to the ports in the init phase.

Note

Note that both the InputPortPlugin and the OutputPortPlugin inherits from the PortPlugin, hence plugins of both types will be initialized.

Parameters:

contextpypz.executors.operator.context.ExecutionContext

__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_logger: ContextLogger
_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

on_entry() None
on_execute() BaseSignal
on_exit() None
class pypz.executors.operator.states.StateOperationRunning(context: ExecutionContext, *args, **kwargs)

Bases: State

This state calls the main processing method of the Operator:

pypz.core.specs.operator.Operator._on_running()

After successful finish of the Operator’s method, the offset commit on all the InputPortPlugin will be invoked.

pypz.core.specs.plugin.InputPortPlugin.commit_current_read_offset()

This ensures that even, if the developer did not commit offsets manually in the implementation, offsets will still be committed.

Parameters:

contextpypz.executors.operator.context.ExecutionContext

__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_logger: ContextLogger
_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

on_entry() None
on_execute() BaseSignal
on_exit() None
class pypz.executors.operator.states.StateOperationShutdown(context: ExecutionContext, *args, **kwargs)

Bases: State

This state shuts down the operator.

Invoked methods:

  1. pypz.core.specs.operator.Operator._on_shutdown()

  2. pypz.core.specs.plugin.PortPlugin._on_port_close()

This order of execution guarantees that the Operator’s implementation is still having access to the ports in the shutdown phase.

Note

Note that both the InputPortPlugin and the OutputPortPlugin inherits from the PortPlugin, hence plugins of both types will be shut down.

Parameters:

contextpypz.executors.operator.context.ExecutionContext

__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_logger: ContextLogger
_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

on_entry() None
on_execute() BaseSignal
on_exit() None
class pypz.executors.operator.states.StateResourceCreation(context: ExecutionContext, *args, **kwargs)

Bases: State

This state is responsible to invoke the resource creation related methods.

Invoked methods:

pypz.core.specs.plugin.ResourceHandlerPlugin._on_resource_creation()

Parameters:

contextpypz.executors.operator.context.ExecutionContext

__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_logger: ContextLogger
_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

on_entry() None
on_execute() BaseSignal
on_exit() None
class pypz.executors.operator.states.StateResourceDeletion(context: ExecutionContext, *args, **kwargs)

Bases: State

This state is responsible to invoke the resource deletion related methods.

Invoked methods:

pypz.core.specs.plugin.ResourceHandlerPlugin._on_resource_deletion()

Parameters:

contextpypz.executors.operator.context.ExecutionContext

__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_logger: ContextLogger
_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

on_entry() None
on_execute() BaseSignal
on_exit() None
class pypz.executors.operator.states.StateServiceShutdown(context: ExecutionContext, *args, **kwargs)

Bases: State

This state is responsible to invoke the service shutdown related methods.

Invoked methods:

pypz.core.specs.plugin.ServicePlugin._on_service_shutdown()

Parameters:

contextpypz.executors.operator.context.ExecutionContext

__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_logger: ContextLogger
_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

on_entry() None
on_execute() BaseSignal
on_exit() None
class pypz.executors.operator.states.StateServiceStart(context: ExecutionContext, *args, **kwargs)

Bases: State

This state is responsible to invoke the service start related methods.

Invoked methods:

pypz.core.specs.plugin.ServicePlugin._on_service_start()

Parameters:

contextpypz.executors.operator.context.ExecutionContext

__executor: ThreadPoolExecutor

Handles the execution of plugins’ corresponding methods, which can run parallel

_abc_impl = <_abc._abc_data object>
_context: ExecutionContext

Holds the reference to the actual operator instance that shall be executed

_logger: ContextLogger
_prev_state: State | None

Contains the information about the previous state the state machine was in

_reason: BaseSignal | None

Contains the information about the signal that drove the state machine into this state i.e., the reason of this state

_response_collector: dict[Callable[[], bool], bool]

Stores the responses of the plugin objects for each instance. Used to prevent finished instances to be re-scheduled

_state_entry_time_ms: int

Stores the state entry epoch time

_transition_map: dict[Type[BaseSignal], State]

Contains the possible transitions from this state

on_entry() None
on_execute() BaseSignal
on_exit() None