Skip to content
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

Cannot call "send" once a close message has been sent. #8287

Closed
1 task done
tchaton opened this issue May 14, 2024 · 2 comments
Closed
1 task done

Cannot call "send" once a close message has been sent. #8287

tchaton opened this issue May 14, 2024 · 2 comments
Labels
bug Something isn't working pending clarification

Comments

@tchaton
Copy link

tchaton commented May 14, 2024

Describe the bug

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 240, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
    return await self.app(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/middleware/errors.py", line 151, in __call__
    await self.app(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/middleware/cors.py", line 77, in __call__
    await self.app(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 373, in handle
    await self.app(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 96, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 94, in app
    await func(session)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/fastapi/routing.py", line 348, in app
    await dependant.call(**values)
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/gradio/routes.py", line 265, in notify_changes
    await websocket.close()
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/websockets.py", line 203, in close
    await self.send(
  File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/websockets.py", line 112, in send
    raise RuntimeError('Cannot call "send" once a close message has been sent.')
RuntimeError: Cannot call "send" once a close message has been sent.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import os
import gradio as gr
import torch
import requests
from torchvision import transforms

model = torch.hub.load("pytorch/vision:v0.6.0", "resnet18", weights='ResNet18_Weights.IMAGENET1K_V1').eval()
response = requests.get("https://git.io/JJkYN")
labels = response.text.split("\n")


def predict(inp):
    inp = transforms.ToTensor()(inp).unsqueeze(0)
    with torch.no_grad():
        prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
        confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
    return confidences


dir_path = os.path.dirname(os.path.realpath(__file__))
demo = gr.Interface(
    fn=predict,
    inputs=gr.components.Image(type="pil"),
    outputs=gr.components.Label(num_top_classes=3),
    examples=[[f"{dir_path}/cheetah.jpg"]],
)

demo.launch()

Screenshot

NA

Logs

NA

System Info

~ python -V
Python 3.10.10
⚡ ~ pip list | grep gradio
gradio                    3.50.2
gradio_client             0.6.1

Severity

I can work around it

@tchaton tchaton added the bug Something isn't working label May 14, 2024
@freddyaboulton
Copy link
Collaborator

Hi @tchaton ? Does this happen in the latest version (4.30.1)? We don't release back-patches for previous versions.

@abidlabs
Copy link
Member

Going to close for now, can reopen with clarification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending clarification
Projects
None yet
Development

No branches or pull requests

3 participants