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

feat: add context manager support for bentoml.client #3402

Merged
merged 2 commits into from Jan 13, 2023

Conversation

y1450
Copy link
Contributor

@y1450 y1450 commented Jan 8, 2023

  • 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.

What does this PR address?

Fixes #(issue)

Before submitting:

@y1450 y1450 requested a review from a team as a code owner January 8, 2023 01:28
@y1450 y1450 requested review from aarnphm and removed request for a team January 8, 2023 01:28
@y1450
Copy link
Contributor Author

y1450 commented Jan 8, 2023

I could not find any existing test cases for initial PR (#3028).
One can add tests for clean up and setup, However going through the existing code, I could not infer what exactly need to be cleanup.
My first idea was HTTP connection, but it is already managed through session which is created on each call.

async with aiohttp.ClientSession(self.server_url) as sess:

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]]))  

Copy link
Member

@aarnphm aarnphm left a 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.

src/bentoml/client.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jan 12, 2023

Codecov Report

Merging #3402 (cc76526) into main (75daa5a) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/bentoml/client.py 0.00% <0.00%> (ø)

@y1450 y1450 force-pushed the 3288-client-context-manager branch 2 times, most recently from 0f63775 to fda8133 Compare January 13, 2023 12:15
- 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.
@y1450 y1450 force-pushed the 3288-client-context-manager branch from fda8133 to cc76526 Compare January 13, 2023 12:19
Copy link
Member

@aarnphm aarnphm left a 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.

@aarnphm aarnphm changed the title feat: bentoml.client add context manager support. (#3288) feat: add context manager support for bentoml.client Jan 13, 2023
@aarnphm aarnphm merged commit 76cb310 into bentoml:main Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants