1
- import atexit
2
1
import logging
3
- from threading import Event , Thread
2
+ from threading import Thread
4
3
from time import sleep
5
4
6
5
import schedule
12
11
LOGGER = logging .getLogger ("SentryWrapper" )
13
12
14
13
15
- def on_exit (event , thread ):
16
- event .set ()
17
- thread .join ()
18
-
19
-
20
14
class ControllerClient (Thread ):
21
- def __init__ (self , stop , config , metric , * args , ** kwargs ) -> None :
15
+ def __init__ (self , config , metric , * args , ** kwargs ) -> None :
22
16
self .poll_interval = kwargs .pop ("poll_interval" )
23
17
self .metric_interval = kwargs .pop ("metric_interval" )
24
18
self .controller_endpoint = kwargs .pop ("controller_endpoint" )
25
19
self .metric_endpoint = kwargs .pop ("metric_endpoint" )
26
20
self .app_key = kwargs .pop ("app_key" )
27
- self .stop : Event = stop
28
21
self .config : Config = config
29
22
self .metrics : Metric = metric
30
23
self .session = CachedSession (backend = "memory" , cache_control = True )
@@ -37,7 +30,7 @@ def run(self):
37
30
sleep (5 )
38
31
schedule .every (self .poll_interval ).seconds .do (self .update_config )
39
32
schedule .every (self .metric_interval ).seconds .do (self .update_metrics )
40
- while not self . stop . is_set () :
33
+ while True :
41
34
schedule .run_pending ()
42
35
sleep (1 )
43
36
@@ -79,19 +72,11 @@ def update_metrics(self):
79
72
80
73
class TraceSampler :
81
74
def __init__ (self , * args , ** kwargs ) -> None :
82
- self .stop = Event ()
83
75
self .config = Config ()
84
76
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 )
88
78
self .controller .start ()
89
79
90
- atexit .register (on_exit , self .stop , self .controller )
91
-
92
- def __del__ (self ):
93
- on_exit (self .stop , self .controller )
94
-
95
80
def __call__ (self , sampling_context ):
96
81
if sampling_context :
97
82
if "wsgi_environ" in sampling_context :
0 commit comments