Skip to content

Commit 88880be

Browse files
authored
ref(profiling): Remove use of threading.Event (getsentry#1864)
Using threading.Event here is too much, just a bool is enough.
1 parent 1268e2a commit 88880be

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

sentry_sdk/profiler.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def __init__(self, frequency):
629629
super(ThreadScheduler, self).__init__(frequency=frequency)
630630

631631
# used to signal to the thread that it should stop
632-
self.event = threading.Event()
632+
self.running = False
633633

634634
# make sure the thread is a daemon here otherwise this
635635
# can keep the application running after other threads
@@ -638,21 +638,19 @@ def __init__(self, frequency):
638638

639639
def setup(self):
640640
# type: () -> None
641+
self.running = True
641642
self.thread.start()
642643

643644
def teardown(self):
644645
# type: () -> None
645-
self.event.set()
646+
self.running = False
646647
self.thread.join()
647648

648649
def run(self):
649650
# type: () -> None
650651
last = time.perf_counter()
651652

652-
while True:
653-
if self.event.is_set():
654-
break
655-
653+
while self.running:
656654
self.sampler()
657655

658656
# some time may have elapsed since the last time
@@ -694,29 +692,27 @@ def __init__(self, frequency):
694692
super(GeventScheduler, self).__init__(frequency=frequency)
695693

696694
# used to signal to the thread that it should stop
697-
self.event = threading.Event()
695+
self.running = False
698696

699697
# Using gevent's ThreadPool allows us to bypass greenlets and spawn
700698
# native threads.
701699
self.pool = ThreadPool(1)
702700

703701
def setup(self):
704702
# type: () -> None
703+
self.running = True
705704
self.pool.spawn(self.run)
706705

707706
def teardown(self):
708707
# type: () -> None
709-
self.event.set()
708+
self.running = False
710709
self.pool.join()
711710

712711
def run(self):
713712
# type: () -> None
714713
last = time.perf_counter()
715714

716-
while True:
717-
if self.event.is_set():
718-
break
719-
715+
while self.running:
720716
self.sampler()
721717

722718
# some time may have elapsed since the last time

0 commit comments

Comments
 (0)