Skip to content

Commit

Permalink
fix(server): deprecate client and cache get_client
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <[email protected]>
  • Loading branch information
aarnphm committed Feb 9, 2023
1 parent 5f7ebe3 commit e5735b5
Showing 1 changed file with 17 additions and 9 deletions.
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

0 comments on commit e5735b5

Please sign in to comment.