diff options
Diffstat (limited to 'nova/utils.py')
-rw-r--r-- | nova/utils.py | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/nova/utils.py b/nova/utils.py index 664056a09f..b5d45c58b5 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -632,15 +632,13 @@ def _serialize_profile_info(): return trace_info -def spawn(func, *args, **kwargs): - """Passthrough method for eventlet.spawn. - - This utility exists so that it can be stubbed for testing without - interfering with the service spawns. +def pass_context(runner, func, *args, **kwargs): + """Generalised passthrough method - It will also 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 this method to spawn a new thread. + 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 """ _context = common_context.get_current() profiler_info = _serialize_profile_info() @@ -655,11 +653,11 @@ def spawn(func, *args, **kwargs): profiler.init(**profiler_info) return func(*args, **kwargs) - return eventlet.spawn(context_wrapper, *args, **kwargs) + return runner(context_wrapper, *args, **kwargs) -def spawn_n(func, *args, **kwargs): - """Passthrough method for eventlet.spawn_n. +def spawn(func, *args, **kwargs): + """Passthrough method for eventlet.spawn. This utility exists so that it can be stubbed for testing without interfering with the service spawns. @@ -668,25 +666,26 @@ def spawn_n(func, *args, **kwargs): the store on the new thread. This allows for continuity in logging the context when using this method to spawn a new thread. """ - _context = common_context.get_current() - profiler_info = _serialize_profile_info() - @functools.wraps(func) - def context_wrapper(*args, **kwargs): - # NOTE: If update_store is not called after spawn_n it won't be - # available for the logger to pull from threadlocal storage. - if _context is not None: - _context.update_store() - if profiler_info and profiler: - profiler.init(**profiler_info) - func(*args, **kwargs) + return pass_context(eventlet.spawn, func, *args, **kwargs) + + +def spawn_n(func, *args, **kwargs): + """Passthrough method for eventlet.spawn_n. + + This utility exists so that it can be stubbed for testing without + interfering with the service spawns. - eventlet.spawn_n(context_wrapper, *args, **kwargs) + It will also 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 this method to spawn a new thread. + """ + pass_context(eventlet.spawn_n, func, *args, **kwargs) def tpool_execute(func, *args, **kwargs): """Run func in a native thread""" - tpool.execute(func, *args, **kwargs) + return pass_context(tpool.execute, func, *args, **kwargs) def is_none_string(val): |