Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): deprecate client and cache get_client #3547

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/bentoml/_internal/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,35 @@
if TYPE_CHECKING:
from types import TracebackType

from bentoml.client import Client


logger = logging.getLogger(__name__)


@attr.frozen
@attr.define
class ServerHandle:
process: subprocess.Popen[bytes]
host: str
port: int
timeout: int = attr.field(default=10)
timeout: int = 10
_client: Client | None = None

def client(self):
def client(self) -> Client:
logger.warning(
"'ServerHandle.client()' is deprecated, use 'ServerHandle.get_client()' instead"
)
return self.get_client()

def get_client(self):
from bentoml.client import Client
def get_client(self) -> Client:
if self._client is None:
from bentoml.client import Client

Client.wait_until_server_is_ready(
host=self.host, port=self.port, timeout=self.timeout
)
return Client.from_url(f"http://localhost:{self.port}")
Client.wait_until_server_is_ready(
host=self.host, port=self.port, timeout=self.timeout
)
self._client = Client.from_url(f"http://localhost:{self.port}")
return self._client

def stop(self) -> None:
self.process.terminate()
Expand Down