-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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(async): add AsyncClient and AsyncFlow #1463
Conversation
Latency summaryCurrent PR yields:
Breakdown
Backed by latency-tracking. Further commits will update this comment. |
Codecov Report
@@ Coverage Diff @@
## master #1463 +/- ##
==========================================
+ Coverage 81.43% 82.80% +1.36%
==========================================
Files 112 110 -2
Lines 6616 6381 -235
==========================================
- Hits 5388 5284 -104
+ Misses 1228 1097 -131
Continue to review full report at Codecov.
|
jina/helper.py
Outdated
from .excepts import BadClient | ||
raise BadClient('something wrong when running the eventloop, result can not be retrieved') | ||
else: | ||
raise RuntimeError('you have an eventloop running but not using jupyter/ipython, ' |
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.
jinad
runs inside fastapi+uvicorn
which has a default event loop (again based on uvloop). Why do we want to raise a RuntimeError
?
import numpy as np | ||
|
||
|
||
class AsyncFlow(Flow): |
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.
Should we implement an async context manager for AsyncFlow?
async with AsyncFlow().add() as f:
await f.index(['abc'])
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.
no. async with
is only implemented when one wants to waive the control during __enter__
__exit__
. We don't have such needs.
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.
This is because we have taken special care not to propagate the async...await
to the caller. e.g. - Client
and AsyncClient
should be context managers, so that they can be used outside a Flow with ease. Similarly GatewayPea
& RESTGatewayPea
can be an async context manager, even though I don't see heavy usage for the same.
see docstring for details