File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change 11import os
2- import time
32import warnings
4- from threading import Thread , Lock
3+ from threading import Thread , Lock , Event
54from contextlib import contextmanager
65
76import sentry_sdk
@@ -162,7 +161,7 @@ def __init__(
162161 self ._thread_lock = Lock ()
163162 self ._aggregate_lock = Lock ()
164163 self ._thread_for_pid = None # type: Optional[int]
165- self ._running = True
164+ self .__shutdown_requested = Event ()
166165
167166 def flush (self ):
168167 # type: (...) -> None
@@ -208,10 +207,10 @@ def _ensure_running(self):
208207
209208 def _thread ():
210209 # type: (...) -> None
211- while self . _running :
212- time . sleep ( self . flush_interval )
213- if self ._running :
214- self .flush ()
210+ running = True
211+ while running :
212+ running = not self .__shutdown_requested . wait ( self . flush_interval )
213+ self .flush ()
215214
216215 thread = Thread (target = _thread )
217216 thread .daemon = True
@@ -220,7 +219,7 @@ def _thread():
220219 except RuntimeError :
221220 # Unfortunately at this point the interpreter is in a state that no
222221 # longer allows us to spawn a thread and we have to bail.
223- self ._running = False
222+ self .__shutdown_requested . set ()
224223 return None
225224
226225 self ._thread = thread
@@ -271,7 +270,7 @@ def add_session(
271270
272271 def kill (self ):
273272 # type: (...) -> None
274- self ._running = False
273+ self .__shutdown_requested . set ()
275274
276275 def __del__ (self ):
277276 # type: (...) -> None
You can’t perform that action at this time.
0 commit comments