Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 39 additions & 36 deletions gradio/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,49 +220,52 @@ async def call_prediction(self, event: Event):
return response

async def process_event(self, event: Event) -> None:
client_awake = await self.gather_event_data(event)
if not client_awake:
return
client_awake = await self.send_message(event, {"msg": "process_starts"})
if not client_awake:
return
begin_time = time.time()
response = await self.call_prediction(event)
if response.json.get("is_generating", False):
while response.json.get("is_generating", False):
old_response = response
try:
client_awake = await self.gather_event_data(event)
if not client_awake:
return
client_awake = await self.send_message(event, {"msg": "process_starts"})
if not client_awake:
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

while response.json.get("is_generating", False):
old_response = response
await self.send_message(
event,
{
"msg": "process_generating",
"output": old_response.json,
"success": old_response.status == 200,
},
)
response = await self.call_prediction(event)
await self.send_message(
event,
{
"msg": "process_generating",
"msg": "process_completed",
"output": old_response.json,
"success": old_response.status == 200,
},
)
response = await self.call_prediction(event)
await self.send_message(
event,
{
"msg": "process_completed",
"output": old_response.json,
"success": old_response.status == 200,
},
)
else:
await self.send_message(
event,
{
"msg": "process_completed",
"output": response.json,
"success": response.status == 200,
},
)
end_time = time.time()
if response.status == 200:
self.update_estimation(end_time - begin_time)

await event.disconnect()
await self.clean_event(event)
else:
await self.send_message(
event,
{
"msg": "process_completed",
"output": response.json,
"success": response.status == 200,
},
)
end_time = time.time()
if response.status == 200:
self.update_estimation(end_time - begin_time)
finally:
try:
await event.disconnect()
finally:
await self.clean_event(event)

async def send_message(self, event, data: Dict) -> bool:
try:
Expand Down