Closed abidlabs closed 2 weeks ago
• | Name | Status | URL |
---|---|---|---|
Spaces | ready! | Spaces preview | |
Website | ready! | Website preview | |
:unicorn: | Changes | detected! | Details |
Install Gradio from this PR
pip install https://gradio-builds.s3.amazonaws.com/9cd5a091da9a9fd09d639e8bc1f3288454d2a44b/gradio-4.28.3-py3-none-any.whl
Install Gradio Python Client from this PR
pip install "gradio-client @ git+https://github.com/gradio-app/gradio@9cd5a091da9a9fd09d639e8bc1f3288454d2a44b#subdirectory=client/python"
Package | Version |
---|---|
gradio |
patch |
gradio_client |
patch |
Convert sse calls in client from async to sync
Maintainers or the PR author can modify the PR title to modify this entry.
This looks good to me @abidlabs! Tested some local demos and everything looks good. One comment I have is whether we can stop raising CancelledError and just return now? That should stop the job in the threadpool no?
Yup I think you're right
One comment I have is whether we can stop raising CancelledError and just return now? That should stop the job in the threadpool no?
Ok so I spent some time on this, but if we stop raising CancelledError and instead return None
, then several upstream methods fail. The basic problem is we need to decide what job.result()
should produce if the job
is canceled. I think its not a bad idea for it to just raise a CancelledError
as is currently the behavior? We could potentially change this and I'm open to other ideas, but I think we can make that part of another PR, perhaps as we address: https://github.com/gradio-app/gradio/issues/8188
I'll go ahead and merge this in but open to suggestions on this @freddyaboulton
Thanks for the reviews @aliabid94 and @freddyaboulton!
great work :+1:
This converts all of the HTTP / SSE calls in the python client from async to sync. There was no benefit in keeping them async as we would convert them to synchronous calls using
utils.synchronize_async
anyways and the use of this method was preventing the client from being used in environments that have their own async event management like gunicorn/gevent.Closes: https://github.com/gradio-app/gradio/issues/7581
To test, create a file called
test.py
with the following code:Then run:
gunicorn -k gevent -w 1 test:app --bind 0.0.0.0:5000
Then visit
http://localhost:5000/gen
and you should see a valid greeting.Note: I didn't change the ws calls since websocket.send/receive are async by nature and so we'd have to do a workaround like
utils.synchronize_async
anyways to support them. So if you use the Client to connect to Gradio apps running 3.x ("compatibility mode"), it will still use the async client.