Skip to content

Commit c541bd7

Browse files
committed
ref(transport): Make kill optionally return a task for async
Make kill optionally return a task for async transport. This allows for a blocking kill operation if the caller is in an async context. GH-4582
1 parent 21cde52 commit c541bd7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sentry_sdk/transport.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,19 +781,19 @@ def _make_pool(
781781

782782
return httpcore.AsyncConnectionPool(**opts)
783783

784-
def kill(self: Self) -> None:
784+
def kill(self: Self) -> Optional[asyncio.Task[None]]: # type: ignore
785785

786786
logger.debug("Killing HTTP transport")
787787
self._worker.kill()
788788
for task in self.background_tasks:
789789
task.cancel()
790790
self.background_tasks.clear()
791791
try:
792-
task = self._loop.create_task(self._pool.aclose()) # type: ignore
793-
self.background_tasks.add(task)
794-
task.add_done_callback(lambda t: self.background_tasks.discard(t))
792+
# Return the pool cleanup task so caller can await it if needed
793+
return self._loop.create_task(self._pool.aclose()) # type: ignore
795794
except RuntimeError:
796795
logger.warning("Event loop not running, aborting kill.")
796+
return None
797797

798798

799799
class HttpTransport(BaseHttpTransport):

0 commit comments

Comments
 (0)