File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
opentelemetry-sdk/src/opentelemetry/sdk/trace Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 1818import concurrent .futures
1919import json
2020import logging
21+ import os
2122import threading
2223import traceback
2324import typing
@@ -238,8 +239,16 @@ def __init__(self, num_threads: int = 2):
238239 # iterating through it on "on_start" and "on_end".
239240 self ._span_processors = () # type: Tuple[SpanProcessor, ...]
240241 self ._lock = threading .Lock ()
241- self ._executor = concurrent .futures .ThreadPoolExecutor (
242- max_workers = num_threads
242+ self ._num_threads = num_threads
243+ self ._executor = self ._build_executor ()
244+ if hasattr (os , "register_at_fork" ):
245+ # Only the main thread is kept in forked processed, the executor
246+ # needs to be re-instantiated to get a fresh pool of threads:
247+ os .register_at_fork (after_in_child = self ._build_executor )
248+
249+ def _build_executor (self ) -> concurrent .futures .ThreadPoolExecutor :
250+ return concurrent .futures .ThreadPoolExecutor (
251+ max_workers = self ._num_threads
243252 )
244253
245254 def add_span_processor (self , span_processor : SpanProcessor ) -> None :
You can’t perform that action at this time.
0 commit comments