@@ -632,15 +632,13 @@ def _serialize_profile_info():
632
632
return trace_info
633
633
634
634
635
- def spawn (func , * args , ** kwargs ):
636
- """Passthrough method for eventlet.spawn.
637
-
638
- This utility exists so that it can be stubbed for testing without
639
- interfering with the service spawns.
635
+ def pass_context (runner , func , * args , ** kwargs ):
636
+ """Generalised passthrough method
640
637
641
- It will also grab the context from the threadlocal store and add it to
642
- the store on the new thread. This allows for continuity in logging the
643
- context when using this method to spawn a new thread.
638
+ It will grab the context from the threadlocal store and add it to
639
+ the store on the runner. This allows for continuity in logging the
640
+ context when using this method to spawn a new thread through the
641
+ runner function
644
642
"""
645
643
_context = common_context .get_current ()
646
644
profiler_info = _serialize_profile_info ()
@@ -655,11 +653,11 @@ def context_wrapper(*args, **kwargs):
655
653
profiler .init (** profiler_info )
656
654
return func (* args , ** kwargs )
657
655
658
- return eventlet . spawn (context_wrapper , * args , ** kwargs )
656
+ return runner (context_wrapper , * args , ** kwargs )
659
657
660
658
661
- def spawn_n (func , * args , ** kwargs ):
662
- """Passthrough method for eventlet.spawn_n .
659
+ def spawn (func , * args , ** kwargs ):
660
+ """Passthrough method for eventlet.spawn .
663
661
664
662
This utility exists so that it can be stubbed for testing without
665
663
interfering with the service spawns.
@@ -668,25 +666,26 @@ def spawn_n(func, *args, **kwargs):
668
666
the store on the new thread. This allows for continuity in logging the
669
667
context when using this method to spawn a new thread.
670
668
"""
671
- _context = common_context .get_current ()
672
- profiler_info = _serialize_profile_info ()
673
669
674
- @functools .wraps (func )
675
- def context_wrapper (* args , ** kwargs ):
676
- # NOTE: If update_store is not called after spawn_n it won't be
677
- # available for the logger to pull from threadlocal storage.
678
- if _context is not None :
679
- _context .update_store ()
680
- if profiler_info and profiler :
681
- profiler .init (** profiler_info )
682
- func (* args , ** kwargs )
670
+ return pass_context (eventlet .spawn , func , * args , ** kwargs )
671
+
672
+
673
+ def spawn_n (func , * args , ** kwargs ):
674
+ """Passthrough method for eventlet.spawn_n.
675
+
676
+ This utility exists so that it can be stubbed for testing without
677
+ interfering with the service spawns.
683
678
684
- eventlet .spawn_n (context_wrapper , * args , ** kwargs )
679
+ It will also grab the context from the threadlocal store and add it to
680
+ the store on the new thread. This allows for continuity in logging the
681
+ context when using this method to spawn a new thread.
682
+ """
683
+ pass_context (eventlet .spawn_n , func , * args , ** kwargs )
685
684
686
685
687
686
def tpool_execute (func , * args , ** kwargs ):
688
687
"""Run func in a native thread"""
689
- tpool .execute ( func , * args , ** kwargs )
688
+ return pass_context ( tpool .execute , func , * args , ** kwargs )
690
689
691
690
692
691
def is_none_string (val ):
0 commit comments