From 56ecab5255d4df1825da31691415353c49acc7fb Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Mon, 23 Jan 2023 15:12:00 -0500 Subject: [PATCH] ref(profiling): Remove use of threading.Event Using threading.Event here is too much, just a bool is enough. --- sentry_sdk/profiler.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/sentry_sdk/profiler.py b/sentry_sdk/profiler.py index d1ac29f10b..0ce44a031b 100644 --- a/sentry_sdk/profiler.py +++ b/sentry_sdk/profiler.py @@ -629,7 +629,7 @@ def __init__(self, frequency): super(ThreadScheduler, self).__init__(frequency=frequency) # used to signal to the thread that it should stop - self.event = threading.Event() + self.running = False # make sure the thread is a daemon here otherwise this # can keep the application running after other threads @@ -638,21 +638,19 @@ def __init__(self, frequency): def setup(self): # type: () -> None + self.running = True self.thread.start() def teardown(self): # type: () -> None - self.event.set() + self.running = False self.thread.join() def run(self): # type: () -> None last = time.perf_counter() - while True: - if self.event.is_set(): - break - + while self.running: self.sampler() # some time may have elapsed since the last time @@ -694,7 +692,7 @@ def __init__(self, frequency): super(GeventScheduler, self).__init__(frequency=frequency) # used to signal to the thread that it should stop - self.event = threading.Event() + self.running = False # Using gevent's ThreadPool allows us to bypass greenlets and spawn # native threads. @@ -702,21 +700,19 @@ def __init__(self, frequency): def setup(self): # type: () -> None + self.running = True self.pool.spawn(self.run) def teardown(self): # type: () -> None - self.event.set() + self.running = False self.pool.join() def run(self): # type: () -> None last = time.perf_counter() - while True: - if self.event.is_set(): - break - + while self.running: self.sampler() # some time may have elapsed since the last time