feat: add context manager support for `bentoml.client`
Address
@@ -20,6 +20,9 @@ from .exceptions import RemoteException
from .exceptions import BentoMLException
from ._internal.service.inference_api import InferenceAPI
+if t.TYPE_CHECKING:
+ from types import TracebackType
+
class Client(ABC):
server_url: str
@@ -85,6 +88,28 @@ class Client(ABC):
raise TimeoutError("The server took too long to get ready")
time.sleep(1)
+ def __enter__(self):
+ return self
+
+ def __exit__(
+ self,
+ exc_type: type[BaseException] | None,
+ exc_value: BaseException | None,
+ traceback: TracebackType | None,
+ ) -> bool | None:
+ pass
+
+ async def __aenter__(self):
+ return self
+
+ async def __aexit__(
+ self,
+ exc_type: type[BaseException] | None,
+ exc_value: BaseException | None,
+ traceback: TracebackType | None,
+ ) -> bool | None:
+ pass
+
@staticmethod
def from_url(server_url: str) -> Client:
server_url = server_url if "://" in server_url else "http://" + server_url
