Skip to content

Commit

Permalink
fix: remove atexit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl0ven committed Jan 10, 2023
1 parent bfe174c commit 1505808
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions sentry_dynamic_sampling_lib/sampler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import atexit
import logging
from threading import Event, Thread
from threading import Thread
from time import sleep

import schedule
Expand All @@ -12,19 +11,13 @@
LOGGER = logging.getLogger("SentryWrapper")


def on_exit(event, thread):
event.set()
thread.join()


class ControllerClient(Thread):
def __init__(self, stop, config, metric, *args, **kwargs) -> None:
def __init__(self, config, metric, *args, **kwargs) -> None:
self.poll_interval = kwargs.pop("poll_interval")
self.metric_interval = kwargs.pop("metric_interval")
self.controller_endpoint = kwargs.pop("controller_endpoint")
self.metric_endpoint = kwargs.pop("metric_endpoint")
self.app_key = kwargs.pop("app_key")
self.stop: Event = stop
self.config: Config = config
self.metrics: Metric = metric
self.session = CachedSession(backend="memory", cache_control=True)
Expand All @@ -37,7 +30,7 @@ def run(self):
sleep(5)
schedule.every(self.poll_interval).seconds.do(self.update_config)
schedule.every(self.metric_interval).seconds.do(self.update_metrics)
while not self.stop.is_set():
while True:
schedule.run_pending()
sleep(1)

Expand Down Expand Up @@ -79,19 +72,11 @@ def update_metrics(self):

class TraceSampler:
def __init__(self, *args, **kwargs) -> None:
self.stop = Event()
self.config = Config()
self.metrics = Metric()
self.controller = ControllerClient(
*args, self.stop, self.config, self.metrics, **kwargs
)
self.controller = ControllerClient(*args, self.config, self.metrics, **kwargs)
self.controller.start()

atexit.register(on_exit, self.stop, self.controller)

def __del__(self):
on_exit(self.stop, self.controller)

def __call__(self, sampling_context):
if sampling_context:
if "wsgi_environ" in sampling_context:
Expand Down

0 comments on commit 1505808

Please sign in to comment.