Skip to content

Commit 4f38a9a

Browse files
committed
fix tests
1 parent ade644a commit 4f38a9a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

sentry_sdk/profiler/continuous_profiler.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ def try_continuous_profiling_auto_start():
123123
if _scheduler is None:
124124
return
125125

126-
# Additionally, we only want this autostart behaviour once per
127-
# process. If the user explicitly calls `stop_profiler`, it should
128-
# be respected and not start the profiler again.
129126
if not _scheduler.is_auto_start_enabled():
130127
return
131128

@@ -145,7 +142,7 @@ def stop_profiler():
145142
if _scheduler is None:
146143
return
147144

148-
_scheduler.teardown()
145+
_scheduler.manual_stop()
149146

150147

151148
def teardown_continuous_profiler():
@@ -195,6 +192,15 @@ def __init__(self, frequency, options, sdk_info, capture_func):
195192

196193
def is_auto_start_enabled(self):
197194
# type: () -> bool
195+
196+
# Ensure that the scheduler only autostarts once per process.
197+
# This is necessary because many web servers use forks to spawn
198+
# additional processes. And the profiler is only spawned on the
199+
# master process, then it often only profiles the main process
200+
# and not the ones where the requests are being handled.
201+
if self.pid == os.getpid():
202+
return False
203+
198204
experiments = self.options.get("_experiments")
199205
if not experiments:
200206
return False
@@ -208,6 +214,10 @@ def manual_start(self):
208214

209215
self.ensure_running()
210216

217+
def manual_stop(self):
218+
# type: () -> None
219+
self.teardown()
220+
211221
def ensure_running(self):
212222
# type: () -> None
213223
raise NotImplementedError

0 commit comments

Comments
 (0)