Skip to content

fix : queue could be blocked#2288

Merged
freddyaboulton merged 6 commits into
gradio-app:mainfrom
SkyTNT:fix-queue-block
Sep 20, 2022
Merged

fix : queue could be blocked#2288
freddyaboulton merged 6 commits into
gradio-app:mainfrom
SkyTNT:fix-queue-block

Conversation

@SkyTNT
Copy link
Copy Markdown
Contributor

@SkyTNT SkyTNT commented Sep 18, 2022

Description

Surround the code in gradio.queue.Queue.process_event with try...finally... to ensure that the processed events in the queue are cleared to avoid the queue being blocked.

Closes: #2261

Checklist:

  • I have performed a self-review of my own code
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Comment thread gradio/queue.py Outdated
return
begin_time = time.time()
response = await self.call_prediction(event)
if response.json.get("is_generating", False):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to know what the best solution is since we don't have a reproducer. However, looking at the code for the Response class, the json_response_data is not set only if there is an exception raised while sending the request. Given that, I wonder if the better solution is to check whether response.is_valid() or response.has_exception prior to accessing the JSON and if it is not valid, send the following message

{"msg": "process_completed",
  "output": {"error": str(response.exception)}
 "success": False
 }

What do you think @aliabid94 @SkyTNT

Copy link
Copy Markdown
Contributor Author

@SkyTNT SkyTNT Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I think we also need to raise response.exception

@freddyaboulton freddyaboulton self-assigned this Sep 19, 2022
@freddyaboulton freddyaboulton mentioned this pull request Sep 20, 2022
6 tasks
@freddyaboulton
Copy link
Copy Markdown
Collaborator

Thank you for the contribution @SkyTNT ! We don't need to raise an exception as the front-end will automatically raise it for us. I added some unit tests too.

@freddyaboulton freddyaboulton merged commit 0c4b136 into gradio-app:main Sep 20, 2022
@SkyTNT SkyTNT deleted the fix-queue-block branch September 20, 2022 22:40
@nttstar
Copy link
Copy Markdown

nttstar commented Sep 24, 2022

Hello, when to update PyPI package to include this PR? It's very critical.

@abidlabs
Copy link
Copy Markdown
Member

Hi @nttstar we should have a release out on Monday or Tuesday, but in the meantime you can try the beta release gradio==3.4b3

@liminghao1630
Copy link
Copy Markdown

Still exist in 3.27.0 @freddyaboulton

2023-04-24 15:39:59,997 - asyncio - ERROR - Task exception was never retrieved
future: <Task finished name='xnedbjj03d_1' coro=<Queue.process_events() done, defined at /Users/drhaogod/miniconda3/envs/daas/lib/python3.10/site-packages/gradio/queueing.py:343> exception=AttributeError("'AsyncRequest' object has no attribute '_json_response_data'")>
Traceback (most recent call last):
  File "/Users/drhaogod/miniconda3/envs/daas/lib/python3.10/site-packages/gradio/queueing.py", line 370, in process_events
    while response.json.get("is_generating", False):
  File "/Users/drhaogod/miniconda3/envs/daas/lib/python3.10/site-packages/gradio/utils.py", line 696, in json
    return self._json_response_data
AttributeError: 'AsyncRequest' object has no attribute '_json_response_data'

python -c "import gradio; print(gradio.__version__)"
3.27.0

@freddyaboulton
Copy link
Copy Markdown
Collaborator

How can we reproduce @liminghao1630 ?

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.

Queue will be blocked if gradio.event_queue.Queue.process_event has an exception

5 participants