Skip to content

Commit 18a0c91

Browse files
mitsuhikountitaker
authored andcommitted
feat: Disable thread joining on transport shutdown if timeout is 0 (#58)
1 parent 6cde369 commit 18a0c91

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

sentry_sdk/transport.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ def capture_event(self, event):
135135

136136
def shutdown(self, timeout, callback=None):
137137
logger.debug("Shutting down HTTP transport orderly")
138-
self._worker.shutdown(timeout, callback)
138+
if timeout <= 0:
139+
self._worker.kill()
140+
else:
141+
self._worker.shutdown(timeout, callback)
139142

140143
def kill(self):
141144
logger.debug("Killing HTTP transport")

sentry_sdk/worker.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,23 @@ def kill(self):
6262
def shutdown(self, timeout, callback=None):
6363
logger.debug("background worker got shutdown request")
6464
with self._lock:
65-
if not self.is_alive:
66-
return
67-
self._queue.put_nowait(_TERMINATOR)
68-
initial_timeout = min(0.1, timeout)
69-
if not self._timed_queue_join(initial_timeout):
70-
pending = self._queue.qsize()
71-
logger.debug("%d event(s) pending on shutdown", pending)
72-
if callback is not None:
73-
callback(pending, timeout)
74-
self._timed_queue_join(timeout - initial_timeout)
65+
if self.is_alive:
66+
self._queue.put_nowait(_TERMINATOR)
67+
if timeout > 0.0:
68+
self._wait_shutdown(timeout, callback)
7569
self._thread = None
70+
self._thread_for_pid = None
7671
logger.debug("background worker shut down")
7772

73+
def _wait_shutdown(self, timeout, callback):
74+
initial_timeout = min(0.1, timeout)
75+
if not self._timed_queue_join(initial_timeout):
76+
pending = self._queue.qsize()
77+
logger.debug("%d event(s) pending on shutdown", pending)
78+
if callback is not None:
79+
callback(pending, timeout)
80+
self._timed_queue_join(timeout - initial_timeout)
81+
7882
def submit(self, callback):
7983
self._ensure_thread()
8084
self._queue.put_nowait(callback)

0 commit comments

Comments
 (0)