Skip to content

Commit ee0b440

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 a827d0d commit ee0b440

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
@@ -783,19 +783,19 @@ def _make_pool(
783783

784784
return httpcore.AsyncConnectionPool(**opts)
785785

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

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

800800

801801
class HttpTransport(BaseHttpTransport):

0 commit comments

Comments
 (0)