From ee341ce9571f696336e3a0db2fd1fb5f4d671308 Mon Sep 17 00:00:00 2001 From: nightcityblade Date: Wed, 24 Jun 2026 11:12:23 +0800 Subject: [PATCH 1/2] fix: document suppressed client cleanup errors Fixes openai/openai-python#3428 --- src/openai/_base_client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/openai/_base_client.py b/src/openai/_base_client.py index 17863bc067..fb5d8cddf6 100644 --- a/src/openai/_base_client.py +++ b/src/openai/_base_client.py @@ -837,7 +837,9 @@ def __del__(self) -> None: try: self.close() except Exception: - pass + # Suppress destructor cleanup errors; object finalizers should not raise + # during garbage collection or interpreter shutdown. + return class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]): @@ -1434,7 +1436,9 @@ def __del__(self) -> None: # TODO(someday): support non asyncio runtimes here asyncio.get_running_loop().create_task(self.aclose()) except Exception: - pass + # Suppress destructor cleanup errors; object finalizers should not raise + # during garbage collection or interpreter shutdown. + return class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]): From 6840ec9ee1509bb25d6c2497740d778209afee8a Mon Sep 17 00:00:00 2001 From: nightcityblade Date: Sat, 27 Jun 2026 23:09:58 +0800 Subject: [PATCH 2/2] fix: log suppressed client cleanup errors --- src/openai/_base_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openai/_base_client.py b/src/openai/_base_client.py index fb5d8cddf6..a38efed706 100644 --- a/src/openai/_base_client.py +++ b/src/openai/_base_client.py @@ -839,7 +839,7 @@ def __del__(self) -> None: except Exception: # Suppress destructor cleanup errors; object finalizers should not raise # during garbage collection or interpreter shutdown. - return + log.debug("Failed to close sync HTTP client during object finalization", exc_info=True) class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]): @@ -1438,7 +1438,7 @@ def __del__(self) -> None: except Exception: # Suppress destructor cleanup errors; object finalizers should not raise # during garbage collection or interpreter shutdown. - return + log.debug("Failed to close async HTTP client during object finalization", exc_info=True) class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):