From f9eb35a3842e930a9baea21d794a24c6d247c769 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Fri, 25 Apr 2025 12:51:26 +0200 Subject: [PATCH] Make nova.utils.pass_context private All our thread spawning should pass the context and all should go through either spawn to use the default executor or spawn_on with a specific executor. Right now pass_context is only called locally in the utils module. We make it private to signal that it is intentional. This is a pure refactor with two steps: * remove the public pass_context as it is unused by removing it from the internall call chain of spawn and spawn_on * rename _pass_context_wrapper This change does not effect any existing behavior so no test changes were needed. Change-Id: I5ad19b5c1a6d489c0f7df7fcbd9f87858b03760c Signed-off-by: Balazs Gibizer --- nova/utils.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/nova/utils.py b/nova/utils.py index 1227146ac4..c95e1c1be0 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -675,12 +675,14 @@ def _serialize_profile_info(): return trace_info -def _pass_context_wrapper(func): +def _pass_context(runner, func, *args, **kwargs): """Generalised passthrough method It will grab the context from the threadlocal store and add it to - the store on the new thread. This allows for continuity in logging the - context when using the returned method is executed on a new thread. + the store on the runner. This allows for continuity in logging the + context when using this method to spawn a new thread through the + runner function """ + _context = common_context.get_current() profiler_info = _serialize_profile_info() @@ -694,18 +696,7 @@ def _pass_context_wrapper(func): profiler.init(**profiler_info) return func(*args, **kwargs) - return context_wrapper - - -def pass_context(runner, func, *args, **kwargs): - """Generalised passthrough method - It will grab the context from the threadlocal store and add it to - the store on the runner. This allows for continuity in logging the - context when using this method to spawn a new thread through the - runner function - """ - - return runner(_pass_context_wrapper(func), *args, **kwargs) + return runner(context_wrapper, *args, **kwargs) def spawn(func, *args, **kwargs) -> futurist.Future: @@ -748,12 +739,12 @@ def spawn_on(executor, func, *args, **kwargs) -> futurist.Future: "queued. If this happens repeatedly then the size of the pool is " "too small for the load or there are stuck threads filling the " "pool.", executor.name, func) - return pass_context(executor.submit, func, *args, **kwargs) + return _pass_context(executor.submit, func, *args, **kwargs) def tpool_execute(func, *args, **kwargs): """Run func in a native thread""" - return pass_context(tpool.execute, func, *args, **kwargs) + return _pass_context(tpool.execute, func, *args, **kwargs) def is_none_string(val):