Skip to content
Prev Previous commit
Next Next commit
add comments
  • Loading branch information
sentrivana committed Nov 2, 2023
commit 25b87a6db3092f5edbaa8f90c3b119bc1ca14cc7
7 changes: 7 additions & 0 deletions sentry_sdk/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def __init__(self, transport, interval=10):

def _ensure_running(self):
# type: () -> None
"""
Check that the monitor has an active thread to run in, or create one if not.

Note that this might fail (e.g. in Python 3.12 it's not possible to
spawn new threads at interpreter shutdown). In that case self._running
will be False after running this function.
"""
if self._thread_for_pid == os.getpid() and self._thread is not None:
return None

Expand Down
11 changes: 10 additions & 1 deletion sentry_sdk/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ def ensure_running(self):
def start_profiling(self, profile):
# type: (Profile) -> None
self.ensure_running()
self.new_profiles.append(profile)
if self.running:
self.new_profiles.append(profile)

def stop_profiling(self, profile):
# type: (Profile) -> None
Expand Down Expand Up @@ -898,6 +899,14 @@ def teardown(self):

def ensure_running(self):
# type: () -> None
"""
Check that the profiler has an active thread to run in, and start one if
that's not the case.

Note that this might fail (e.g. in Python 3.12 it's not possible to
spawn new threads at interpreter shutdown). In that case self.running
will be False after running this function.
"""
pid = os.getpid()

# is running on the right process
Expand Down
7 changes: 7 additions & 0 deletions sentry_sdk/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ def flush(self):

def _ensure_running(self):
# type: (...) -> None
"""
Check that we have an active thread to run in, or create one if not.

Note that this might fail (e.g. in Python 3.12 it's not possible to
spawn new threads at interpreter shutdown). In that case self._running
will be False after running this function.
"""
if self._thread_for_pid == os.getpid() and self._thread is not None:
return None
with self._thread_lock:
Expand Down