@@ -317,15 +317,14 @@ def close(self):
317317def _initialize ():
318318 """Initialize the telemetry system if not already initialized"""
319319 global _initialized , _executor
320- with _lock :
321- if not _initialized :
322- _clients .clear ()
323- _executor = ThreadPoolExecutor (max_workers = 10 )
324- _install_exception_hook ()
325- _initialized = True
326- logger .debug (
327- "Telemetry system initialized with thread pool (max_workers=10)"
328- )
320+ if not _initialized :
321+ _clients .clear ()
322+ _executor = ThreadPoolExecutor (max_workers = 10 )
323+ _install_exception_hook ()
324+ _initialized = True
325+ logger .debug (
326+ "Telemetry system initialized with thread pool (max_workers=10)"
327+ )
329328
330329
331330def _install_exception_hook ():
@@ -356,9 +355,8 @@ def initialize_telemetry_client(
356355):
357356 """Initialize a telemetry client for a specific connection if telemetry is enabled"""
358357 try :
359- _initialize ()
360-
361358 with _lock :
359+ _initialize ()
362360 if session_id_hex not in _clients :
363361 logger .debug (
364362 "Creating new TelemetryClient for connection %s" , session_id_hex
@@ -371,8 +369,10 @@ def initialize_telemetry_client(
371369 host_url = host_url ,
372370 executor = _executor ,
373371 )
372+ print ("i have initialized the telemetry client yes" )
374373 else :
375374 _clients [session_id_hex ] = NoopTelemetryClient ()
375+ print ("i have initialized the noop client yes" )
376376 except Exception as e :
377377 logger .debug ("Failed to initialize telemetry client: %s" , e )
378378 # Fallback to NoopTelemetryClient to ensure connection doesn't fail
@@ -397,20 +397,20 @@ def get_telemetry_client(session_id_hex):
397397def close_telemetry_client (session_id_hex ):
398398 """Remove the telemetry client for a specific connection"""
399399 global _initialized , _executor
400+ with _lock :
401+ if session_id_hex in _clients :
402+ logger .debug ("Removing telemetry client for connection %s" , session_id_hex )
403+ telemetry_client = _clients .pop (session_id_hex , None )
404+ telemetry_client .close ()
400405
401- if session_id_hex in _clients :
402- logger .debug ("Removing telemetry client for connection %s" , session_id_hex )
403- telemetry_client = _clients .pop (session_id_hex , None )
404- telemetry_client .close ()
405-
406- # Shutdown executor if no more clients
407- try :
408- if not _clients and _executor :
409- logger .debug (
410- "No more telemetry clients, shutting down thread pool executor"
411- )
412- _executor .shutdown (wait = True )
413- _executor = None
414- _initialized = False
415- except Exception as e :
416- logger .debug ("Failed to shutdown thread pool executor: %s" , e )
406+ # Shutdown executor if no more clients
407+ try :
408+ if not _clients and _executor :
409+ logger .debug (
410+ "No more telemetry clients, shutting down thread pool executor"
411+ )
412+ _executor .shutdown (wait = True )
413+ _executor = None
414+ _initialized = False
415+ except Exception as e :
416+ logger .debug ("Failed to shutdown thread pool executor: %s" , e )
0 commit comments