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
feat: add context manager support for bentoml.client
#3402
Conversation
I could not find any existing test cases for initial PR (#3028). Line 163 in 931dedc
As a testcase I tried this but I am not sure whether it is good test? from bentoml.client import Client
import numpy as np
client = Client.from_url("http://localhost:3000")
client.classify(np.array([[4.9, 3.0, 1.4, 0.2]]))
with Client.from_url("http://localhost:3000") as cl:
print(cl)
# should this give exception or not?
# currently, it executes without any exception.
cl.classify(np.array([[4.9, 3.0, 1.4, 0.2]])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With one minor comment. Otherwise, it is pretty straightforward.
Right now, we don't have a test for our client, but ideally, the client should be used for our tests feature, which is under construction 🚧 from #2968.
I'm also thinking of moving this to #3280 as I refactor and add gRPC support for bentoml.client
.
Codecov Report
@@ Coverage Diff @@
## main #3402 +/- ##
==========================================
- Coverage 33.13% 33.10% -0.04%
==========================================
Files 132 132
Lines 10679 10689 +10
Branches 1777 1778 +1
==========================================
Hits 3539 3539
- Misses 6900 6910 +10
Partials 240 240
|
0f63775
to
fda8133
Compare
- implments `__enter__`,`__exit__`,`__aenter__`and `__aexit__` A dummy implementation is added to support to context protocol as it is required for the 'with' statement. The implementation of exit method is empty as client does not have any persistent connection, each api call is processed in a separate aio.http session.
fda8133
to
cc76526
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contritbutions.
bentoml.client
__enter__
,__exit__
,__aenter__
and__aexit__
A dummy implementation is added to support to context protocol as it is required for the 'with' statement.
The implementation of exit method is empty as client does not have any persistent connection, each api call is processed in a separate aio.http session.
What does this PR address?
Fixes #(issue)
Before submitting:
guide on how to create a pull request.
make format
andmake lint
script have passed (instructions)?those accordingly? Here are documentation guidelines and tips on writting docs.