pynenc.runner.thread_runner¶
Module Contents¶
Classes¶
ThreadRunner is a concrete implementation of BaseRunner that executes tasks in separate threads. |
API¶
- class pynenc.runner.thread_runner.ThreadInfo[source]¶
Bases:
typing.NamedTuple- thread: threading.Thread¶
None
- invocation: pynenc.invocation.dist_invocation.DistributedInvocation¶
None
- class pynenc.runner.thread_runner.ThreadRunner(app: pynenc.app.Pynenc, runner_cache: dict | None = None, runner_context: pynenc.runner.runner_context.RunnerContext | None = None)[source]¶
Bases:
pynenc.runner.base_runner.BaseRunnerThreadRunner is a concrete implementation of BaseRunner that executes tasks in separate threads.
It manages task invocations, handling their execution and lifecycle within individual threads. This runner is suitable for I/O-bound tasks and scenarios where shared memory between tasks is required.
Initialization
- static mem_compatible() bool[source]¶
Indicates if the runner is compatible with in-memory components.
- Returns:
True, as each task is executed in a separate thread with shared 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.
- get_active_child_runner_ids() list[str][source]¶
ThreadRunner doesn’t spawn child processes, so returns empty list.
- _on_start() None[source]¶
Internal method called when the ThreadRunner starts. Initializes the data infrastructures for managing invocations and threads.
- _on_stop() None[source]¶
Internal method called when the ThreadRunner stops. Joins all running threads and updates their invocation statuses.
For alive threads: reroute first while we still own the RUNNING status, then join. If we joined first the task would complete as SUCCESS and the RUNNING→KILLED transition would no longer be valid. For already-dead threads: join (no-op) then reroute, which silently ignores the final status.
- _on_stop_runner_loop() None[source]¶
Internal method called after receiving a signal to stop the runner loop.
- _reclaim_available_slots() int[source]¶
Joins finished threads and returns the number of available thread slots.
- Returns:
An integer representing available thread slots.
- runner_loop_iteration() None[source]¶
Executes one iteration of the ThreadRunner loop. Handles the execution and monitoring of task invocations in separate threads.
- _waiting_for_results(running_invocation_id: pynenc.identifiers.invocation_id.InvocationId, result_invocation_ids: list[pynenc.identifiers.invocation_id.InvocationId], runner_args: dict[str, Any] | None = None) None[source]¶
Handles invocations waiting for results by polling a local final cache instead of pausing threads.
- Parameters:
running_invocation_id – The invocation that is waiting for results.
result_invocation_ids – A list of invocations whose results are being awaited.
runner_args – Additional arguments required for the ThreadRunner.