pynenc.context¶
This module maintains the context of invocations and runners within the Pynenc application.
It stores the current invocation context and runner arguments, facilitating the management and tracking of nested or sub-invocations within different execution environments.
Module Contents¶
Functions¶
Get the current invocation context for the given app. |
|
Set the current invocation context for the given app and returns the previous. |
|
Retrieve the current runner for the given app_id from thread-local storage. |
|
Set the current runner for the given app_id in thread-local storage. |
Data¶
API¶
- pynenc.context.thread_local¶
‘local(…)’
- pynenc.context.sync_inv_context: dict[str, Optional[pynenc.invocation.conc_invocation.ConcurrentInvocation]]¶
None
- pynenc.context._current_runner: dict[str, pynenc.runner.base_runner.BaseRunner]¶
None
- pynenc.context.get_dist_invocation_context(app_id: str) Optional[pynenc.invocation.dist_invocation.DistributedInvocation][source]¶
Get the current invocation context for the given app.
- Parameters:
app_id (str) – The app identifier.
- Result:
The current invocation context for the given app.
- pynenc.context.swap_dist_invocation_context(app_id: str, invocation: Optional[pynenc.invocation.dist_invocation.DistributedInvocation]) Optional[pynenc.invocation.dist_invocation.DistributedInvocation][source]¶
Set the current invocation context for the given app and returns the previous.
- Parameters:
app_id (str) – The app identifier.
invocation (DistributedInvocation) – The invocation to set as the current context.
- pynenc.context.get_current_runner(app_id: str) Optional[pynenc.runner.base_runner.BaseRunner][source]¶
Retrieve the current runner for the given app_id from thread-local storage.
This function allows each thread or process to access its own runner instance, which is critical in multi-process environments like MultiThreadRunner where each process runs a ThreadRunner and needs to reference its own runner instance without conflicting with others.
- Parameters:
app_id – The application identifier.
- Returns:
The current runner instance if set in the current thread/process, else None.
- pynenc.context.set_current_runner(app_id: str, runner: pynenc.runner.base_runner.BaseRunner) None[source]¶
Set the current runner for the given app_id in thread-local storage.
This is used to associate a runner with the current thread or process context, enabling isolated execution environments. It’s particularly essential for MultiThreadRunner, where each spawned process needs to set its own ThreadRunner to avoid cross-process interference.
- Parameters:
app_id – The application identifier.
runner – The runner instance to set.