Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions sentry_sdk/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -694,29 +692,27 @@ 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.
self.pool = ThreadPool(1)

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
Expand Down