Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions sentry_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ def __init__(

self._flusher = None # type: Optional[Union[threading.Thread, ThreadPool]]
self._flusher_pid = None # type: Optional[int]
self._ensure_thread()

def _ensure_thread(self):
# type: (...) -> bool
Expand All @@ -460,6 +459,11 @@ def _ensure_thread(self):
return True

with self._lock:
# Recheck to make sure another thread didn't get here and start the
# the flusher in the meantime
if self._flusher_pid == pid:
return True

self._flusher_pid = pid

if not is_gevent():
Expand All @@ -484,9 +488,9 @@ def _flush_loop(self):
# type: (...) -> None
_in_metrics.set(True)
while self._running or self._force_flush:
self._flush()
if self._running:
self._flush_event.wait(self.FLUSHER_SLEEP_TIME)
self._flush()

def _flush(self):
# type: (...) -> None
Expand Down
1 change: 0 additions & 1 deletion tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def test_timing_basic(sentry_init, capture_envelopes, maybe_monkeypatched_thread
metrics.timing("timing", 3.0, tags={"a": "b"}, timestamp=ts)
Hub.current.flush()

(envelope,) = envelopes
(envelope,) = envelopes
statsd_item, meta_item = envelope.items

Expand Down