From 13bc3c308dcf63d6c9e50417ba5c4f1110d8d04f Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 20 May 2024 16:12:51 -0400 Subject: [PATCH] Add error suppress flag to `current_ipc_ctx()` --- tractor/_state.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tractor/_state.py b/tractor/_state.py index a372983..8c5cca1 100644 --- a/tractor/_state.py +++ b/tractor/_state.py @@ -124,9 +124,15 @@ _ctxvar_Context: ContextVar[Context] = ContextVar( ) -def current_ipc_ctx() -> Context: +def current_ipc_ctx( + error_on_not_set: bool = False, +) -> Context|None: ctx: Context = _ctxvar_Context.get() - if not ctx: + + if ( + not ctx + and error_on_not_set + ): from ._exceptions import InternalError raise InternalError( 'No IPC context has been allocated for this task yet?\n'