Silence annoying OpenAI client shutdown error (#4157)

This commit is contained in:
Stanislav Novosad
2025-12-01 18:02:17 -07:00
committed by GitHub
parent 7100b7e004
commit 4ac82ec25b
3 changed files with 38 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
import asyncio
from openai import DefaultAsyncHttpxClient
class ForgeAsyncHttpxClientWrapper(DefaultAsyncHttpxClient):
"""
Wrapper around OpenAI's AsyncHttpxClientWrapper to mask teardown races.
The upstream `__del__` checks `self.is_closed`, but during interpreter
shutdown httpx internals may already be None, which raises:
AttributeError: 'NoneType' object has no attribute 'CLOSED'
We defensively swallow that destructor error so shutdown logs stay clean.
"""
def __del__(self) -> None:
try:
if self.is_closed:
return
asyncio.get_running_loop().create_task(self.aclose())
except Exception:
pass