pynenc.runner.multi_thread_runner¶
Module Contents¶
Classes¶
MultiThreadRunner spawns separate processes, each running a ThreadRunner. It scales processes based on pending invocations and terminates those that remain idle. |
Functions¶
Runs a ThreadRunner in a separate process. |
API¶
- class pynenc.runner.multi_thread_runner.ProcessState(*args, **kwds)[source]¶
Bases:
enum.Enum- ACTIVE¶
‘active’
- IDLE¶
‘idle’
- class pynenc.runner.multi_thread_runner.ProcessStatus[source]¶
Bases:
typing.NamedTuple- state: pynenc.runner.multi_thread_runner.ProcessState¶
None
- pynenc.runner.multi_thread_runner.thread_runner_process_main(app: pynenc.app.Pynenc, *, shared_status: dict[str, pynenc.runner.multi_thread_runner.ProcessStatus], process_key: str) None[source]¶
Runs a ThreadRunner in a separate process.
- class pynenc.runner.multi_thread_runner.MultiThreadRunner(app: pynenc.app.Pynenc)[source]¶
Bases:
pynenc.runner.base_runner.BaseRunnerMultiThreadRunner spawns separate processes, each running a ThreadRunner. It scales processes based on pending invocations and terminates those that remain idle.
Initialization
- processes: dict[str, multiprocessing.Process]¶
None
- manager: multiprocessing.Manager¶
None
None
- static mem_compatible() bool[source]¶
Indicates if the runner is compatible with in-memory components.
- Returns:
False, as each Thread runs in a separate process with independent memory.
- property max_parallel_slots: int¶
The maximum number of parallel tasks that the runner can handle.
- Returns:
An integer representing the maximum number of parallel tasks, based on config or CPU count.
- _on_stop_runner_loop() None[source]¶
Internal method called after receiving a signal to stop the runner loop. Clears the wait_invocation dictionary.
- _cleanup_dead_processes() None[source]¶
Remove processes that are no longer alive from our tracking dictionaries.
- _scale_up_processes() None[source]¶
Spawns new processes based on enforce_max_processes setting and pending tasks.
- _terminate_idle_processes() None[source]¶
Terminates processes that are idle longer than the configured timeout. A process is considered idle if its shared status indicates IDLE and the time since its last update exceeds idle_timeout_process_sec. Respects enforce_max_processes if enabled.
- waiting_for_results(running_invocation: Optional[pynenc.invocation.dist_invocation.DistributedInvocation], result_invocations: list[pynenc.invocation.dist_invocation.DistributedInvocation], runner_args: Optional[dict[str, Any]] = None) None[source]¶
Handle waiting for results when called from outside any process. This happens when checking results from the main thread or test environment.