From 2ffc89f61238a6880259e6bdd50f34e69c04f070 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:25:36 +0000 Subject: [PATCH] fix(client): only call .close() when needed --- src/groq/_base_client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/groq/_base_client.py b/src/groq/_base_client.py index f4622fbd..c3f36095 100644 --- a/src/groq/_base_client.py +++ b/src/groq/_base_client.py @@ -767,6 +767,9 @@ def __init__(self, **kwargs: Any) -> None: class SyncHttpxClientWrapper(DefaultHttpxClient): def __del__(self) -> None: + if self.is_closed: + return + try: self.close() except Exception: @@ -1334,6 +1337,9 @@ def __init__(self, **kwargs: Any) -> None: class AsyncHttpxClientWrapper(DefaultAsyncHttpxClient): def __del__(self) -> None: + if self.is_closed: + return + try: # TODO(someday): support non asyncio runtimes here asyncio.get_running_loop().create_task(self.aclose())