1- import atexit
21import logging
3- from threading import Event , Thread
2+ from threading import Thread
43from time import sleep
54
65import schedule
1211LOGGER = logging .getLogger ("SentryWrapper" )
1312
1413
15- def on_exit (event , thread ):
16- event .set ()
17- thread .join ()
18-
19-
2014class ControllerClient (Thread ):
21- def __init__ (self , stop , config , metric , * args , ** kwargs ) -> None :
15+ def __init__ (self , config , metric , * args , ** kwargs ) -> None :
2216 self .poll_interval = kwargs .pop ("poll_interval" )
2317 self .metric_interval = kwargs .pop ("metric_interval" )
2418 self .controller_endpoint = kwargs .pop ("controller_endpoint" )
2519 self .metric_endpoint = kwargs .pop ("metric_endpoint" )
2620 self .app_key = kwargs .pop ("app_key" )
27- self .stop : Event = stop
2821 self .config : Config = config
2922 self .metrics : Metric = metric
3023 self .session = CachedSession (backend = "memory" , cache_control = True )
@@ -37,7 +30,7 @@ def run(self):
3730 sleep (5 )
3831 schedule .every (self .poll_interval ).seconds .do (self .update_config )
3932 schedule .every (self .metric_interval ).seconds .do (self .update_metrics )
40- while not self . stop . is_set () :
33+ while True :
4134 schedule .run_pending ()
4235 sleep (1 )
4336
@@ -79,19 +72,11 @@ def update_metrics(self):
7972
8073class TraceSampler :
8174 def __init__ (self , * args , ** kwargs ) -> None :
82- self .stop = Event ()
8375 self .config = Config ()
8476 self .metrics = Metric ()
85- self .controller = ControllerClient (
86- * args , self .stop , self .config , self .metrics , ** kwargs
87- )
77+ self .controller = ControllerClient (* args , self .config , self .metrics , ** kwargs )
8878 self .controller .start ()
8979
90- atexit .register (on_exit , self .stop , self .controller )
91-
92- def __del__ (self ):
93- on_exit (self .stop , self .controller )
94-
9580 def __call__ (self , sampling_context ):
9681 if sampling_context :
9782 if "wsgi_environ" in sampling_context :
0 commit comments