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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use async iteration for progressive outputs #2409
Conversation
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2409-all-demos |
39e77d2
to
7db6ea4
Compare
Great catch @freddyaboulton! Will review shortly |
try: | ||
return next(iterator) | ||
except StopIteration: | ||
# raise a ValueError here because co-routines can't raise StopIteration themselves |
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.
Would StopAsyncIteration
work here? https://stackoverflow.com/questions/50165734/native-coroutine-and-stopiteration
LGTM @freddyaboulton reproduced the original issue and confirmed that this fixes it. Just a comment above in case we can avoid defining a new exception. |
be26744
to
41d39f9
Compare
Thanks for the review and suggestion @abidlabs ! StopAsyncIteration works! |
Description
I noticed that if two different users are running an iterative output demo at the same time, the two demos will not iterate asynchronously. When one demo is iterating, the other is not. This increases the latency of serving outputs to users.
You can see this here:
Main
This branch
The culprit is that
next(iterator)
is not async, so it blocks the event loop for all users.This is the demo code to test:
Checklist:
A note about the CHANGELOG
Hello 馃憢 and thank you for contributing to Gradio!
All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.
Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by
[@myusername](link-to-your-github-profile)
in[PR 11111](https://github.com/gradio-app/gradio/pull/11111)
".If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.