mirror of
https://github.com/bentoml/OpenLLM.git
synced 2026-03-05 07:36:15 -05:00
fix(client): correct destructor the httpx object boht sync and async (#636)
Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>
This commit is contained in:
@@ -46,9 +46,6 @@ class HTTPClient(Client):
|
||||
return {'Authorization': f'Bearer {env}'}
|
||||
return super()._build_auth_headers()
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
@property
|
||||
def _metadata(self):
|
||||
if self.__metadata is None:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# This provides a base shim with httpx and acts as base request
|
||||
from __future__ import annotations
|
||||
import asyncio
|
||||
import email.utils
|
||||
import logging
|
||||
import platform
|
||||
@@ -374,6 +375,9 @@ class Client(BaseClient[httpx.Client, Stream[t.Any]]):
|
||||
def __exit__(self, *args) -> None:
|
||||
self.close()
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
def request(
|
||||
self,
|
||||
response_cls: type[Response],
|
||||
@@ -504,6 +508,16 @@ class AsyncClient(BaseClient[httpx.AsyncClient, AsyncStream[t.Any]]):
|
||||
async def __aexit__(self, *args) -> None:
|
||||
await self.close()
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
loop = asyncio.get_event_loop()
|
||||
if loop.is_running():
|
||||
loop.create_task(self.close())
|
||||
else:
|
||||
loop.run_until_complete(self.close())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
async def request(
|
||||
self,
|
||||
response_cls: type[Response],
|
||||
|
||||
Reference in New Issue
Block a user