process_executor package

Reusable multiprocessing execution support.

class process_executor.ProcessExecutor(worker_factory=None, worker_count=4, start_method=None, *, worker_class=None, worker_args=None, worker_kwargs=None, logger=None)[source]

Bases: object

Generic multiprocessing execution support.

The executor does not know device protocols, transports, or controller semantics. A worker can be created either from an existing worker_factory(context) or directly from an existing controller worker_class.

worker_class exists so device-side controller classes do not need worker-specific wrappers merely to run under multiprocessing.

Parameters:
  • worker_factory (Callable[[SharedContext], Any] | None) – Callable that receives SharedContext and returns one worker-local controller instance.

  • worker_count (int) – Number of worker processes kept ready.

  • start_method (str | None) – Multiprocessing start method. If omitted, Python’s platform default is used.

  • worker_class (Type[Any] | None) – Existing controller class instantiated in each worker.

  • worker_args (Tuple[Any, ...] | None) – Positional arguments passed to worker_class.

  • worker_kwargs (Dict[str, Any] | None) – Keyword arguments passed to worker_class.

  • logger (Any) – Parent-process logger retained by the executor. The logger is not passed into worker processes automatically.

close()[source]

Stop workers and shut down shared resources.

Return type:

None

job(job_id)[source]

Return a snapshot of one job.

Parameters:

job_id (str)

Return type:

Dict[str, Any] | None

jobs()[source]

Return snapshots of all jobs.

Return type:

Dict[str, Dict[str, Any]]

result(job_id)[source]

Return the result of a completed job.

Parameters:

job_id (str)

Return type:

Any

property shared_context: SharedContext

Return the shared context for the parent controller.

state(job_id)[source]

Return a job state.

Parameters:

job_id (str)

Return type:

str | None

submit(handler, *args, **kwargs)[source]

Submit a handler job and immediately return its job ID.

Parameters:
  • handler (str)

  • args (Any)

  • kwargs (Any)

Return type:

str

wait(job_id, timeout_sec=None, interval_sec=0.01)[source]

Explicitly wait for one job and return its result.

Parameters:
  • job_id (str)

  • timeout_sec (float | None)

  • interval_sec (float)

Return type:

Any

worker(worker_id)[source]

Return a snapshot of one worker.

Parameters:

worker_id (str)

Return type:

Dict[str, Any] | None

workers()[source]

Return snapshots of all workers.

Return type:

Dict[str, Dict[str, Any]]

class process_executor.SharedContext(jobs, workers, state, lock)[source]

Bases: object

Shared state and lock for worker processes.

Parameters:
  • jobs (MutableMapping[str, Any]) – Shared mapping containing job metadata.

  • workers (MutableMapping[str, Any]) – Shared mapping containing worker metadata.

  • state (MutableMapping[str, Any]) – Shared mapping reserved for controller-specific shared state.

  • lock (Any) – Process-safe lock shared by all workers.

Submodules

process_executor.executor module

Generic multiprocessing job executor.

class process_executor.executor.ProcessExecutor(worker_factory=None, worker_count=4, start_method=None, *, worker_class=None, worker_args=None, worker_kwargs=None, logger=None)[source]

Bases: object

Generic multiprocessing execution support.

The executor does not know device protocols, transports, or controller semantics. A worker can be created either from an existing worker_factory(context) or directly from an existing controller worker_class.

worker_class exists so device-side controller classes do not need worker-specific wrappers merely to run under multiprocessing.

Parameters:
  • worker_factory (Callable[[SharedContext], Any] | None) – Callable that receives SharedContext and returns one worker-local controller instance.

  • worker_count (int) – Number of worker processes kept ready.

  • start_method (str | None) – Multiprocessing start method. If omitted, Python’s platform default is used.

  • worker_class (Type[Any] | None) – Existing controller class instantiated in each worker.

  • worker_args (Tuple[Any, ...] | None) – Positional arguments passed to worker_class.

  • worker_kwargs (Dict[str, Any] | None) – Keyword arguments passed to worker_class.

  • logger (Any) – Parent-process logger retained by the executor. The logger is not passed into worker processes automatically.

close()[source]

Stop workers and shut down shared resources.

Return type:

None

job(job_id)[source]

Return a snapshot of one job.

Parameters:

job_id (str)

Return type:

Dict[str, Any] | None

jobs()[source]

Return snapshots of all jobs.

Return type:

Dict[str, Dict[str, Any]]

result(job_id)[source]

Return the result of a completed job.

Parameters:

job_id (str)

Return type:

Any

property shared_context: SharedContext

Return the shared context for the parent controller.

state(job_id)[source]

Return a job state.

Parameters:

job_id (str)

Return type:

str | None

submit(handler, *args, **kwargs)[source]

Submit a handler job and immediately return its job ID.

Parameters:
  • handler (str)

  • args (Any)

  • kwargs (Any)

Return type:

str

wait(job_id, timeout_sec=None, interval_sec=0.01)[source]

Explicitly wait for one job and return its result.

Parameters:
  • job_id (str)

  • timeout_sec (float | None)

  • interval_sec (float)

Return type:

Any

worker(worker_id)[source]

Return a snapshot of one worker.

Parameters:

worker_id (str)

Return type:

Dict[str, Any] | None

workers()[source]

Return snapshots of all workers.

Return type:

Dict[str, Dict[str, Any]]

process_executor.shared_context module

Shared context used by worker processes.

class process_executor.shared_context.SharedContext(jobs, workers, state, lock)[source]

Bases: object

Shared state and lock for worker processes.

Parameters:
  • jobs (MutableMapping[str, Any]) – Shared mapping containing job metadata.

  • workers (MutableMapping[str, Any]) – Shared mapping containing worker metadata.

  • state (MutableMapping[str, Any]) – Shared mapping reserved for controller-specific shared state.

  • lock (Any) – Process-safe lock shared by all workers.