2025-12-01

This commit is contained in:
2026-03-17 14:58:51 -06:00
parent 183e865f8b
commit 4b82b57113
6846 changed files with 954887 additions and 162606 deletions
@@ -1,7 +1,6 @@
import os
import time
import warnings
from threading import Thread, Lock
from threading import Thread, Lock, Event
from contextlib import contextmanager
import sentry_sdk
@@ -162,7 +161,7 @@ class SessionFlusher:
self._thread_lock = Lock()
self._aggregate_lock = Lock()
self._thread_for_pid = None # type: Optional[int]
self._running = True
self.__shutdown_requested = Event()
def flush(self):
# type: (...) -> None
@@ -208,10 +207,10 @@ class SessionFlusher:
def _thread():
# type: (...) -> None
while self._running:
time.sleep(self.flush_interval)
if self._running:
self.flush()
running = True
while running:
running = not self.__shutdown_requested.wait(self.flush_interval)
self.flush()
thread = Thread(target=_thread)
thread.daemon = True
@@ -220,7 +219,7 @@ class SessionFlusher:
except RuntimeError:
# Unfortunately at this point the interpreter is in a state that no
# longer allows us to spawn a thread and we have to bail.
self._running = False
self.__shutdown_requested.set()
return None
self._thread = thread
@@ -229,7 +228,8 @@ class SessionFlusher:
return None
def add_aggregate_session(
self, session # type: Session
self,
session, # type: Session
):
# type: (...) -> None
# NOTE on `session.did`:
@@ -260,7 +260,8 @@ class SessionFlusher:
state["exited"] = state.get("exited", 0) + 1
def add_session(
self, session # type: Session
self,
session, # type: Session
):
# type: (...) -> None
if session.session_mode == "request":
@@ -271,8 +272,4 @@ class SessionFlusher:
def kill(self):
# type: (...) -> None
self._running = False
def __del__(self):
# type: (...) -> None
self.kill()
self.__shutdown_requested.set()