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

RuntimeError in stream_generator.py example #109

Open
redb0 opened this issue Sep 23, 2024 · 0 comments
Open

RuntimeError in stream_generator.py example #109

redb0 opened this issue Sep 23, 2024 · 0 comments

Comments

@redb0
Copy link

redb0 commented Sep 23, 2024

I run example stream_generator.py, but when I call GET /sse in swagger, an error appears:

ERROR:    Exception in ASGI application
  + Exception Group Traceback (most recent call last):
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 406, in run_asgi
  |     result = await app(  # type: ignore[func-returns-value]
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
  |     return await self.app(scope, receive, send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/uvicorn/middleware/message_logger.py", line 84, in __call__
  |     raise exc from None
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/uvicorn/middleware/message_logger.py", line 80, in __call__
  |     await self.app(scope, inner_receive, inner_send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/fastapi/applications.py", line 1054, in __call__
  |     await super().__call__(scope, receive, send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/applications.py", line 113, in __call__
  |     await self.middleware_stack(scope, receive, send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 187, in __call__
  |     raise exc
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 165, in __call__
  |     await self.app(scope, receive, _send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
  |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
  |     raise exc
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
  |     await app(scope, receive, sender)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 715, in __call__
  |     await self.middleware_stack(scope, receive, send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 735, in app
  |     await route.handle(scope, receive, send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 288, in handle
  |     await self.app(scope, receive, send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 76, in app
  |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
  |     raise exc
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
  |     await app(scope, receive, sender)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 74, in app
  |     await response(scope, receive, send)
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/sse_starlette/sse.py", line 289, in __call__
  |     await wrap(partial(self.listen_for_disconnect, receive))
  |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 736, in __aexit__
  |     raise BaseExceptionGroup(
  | exceptiongroup.ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/sse_starlette/sse.py", line 278, in wrap
    |     await func()
    |   File "/home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/sse_starlette/sse.py", line 258, in stream_response
    |     async for data in self.body_iterator:
    |   File "/home/voronov/projects/test_2/t.py", line 20, in __anext__
    |     return await self._queue.get()
    |   File "/usr/lib/python3.9/asyncio/queues.py", line 166, in get
    |     await getter
    | RuntimeError: Task <Task pending name='sse_starlette.sse.EventSourceResponse.__call__.<locals>.wrap' coro=<EventSourceResponse.__call__.<locals>.wrap() running at /home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/sse_starlette/sse.py:278> cb=[TaskGroup._spawn.<locals>.task_done() at /home/voronov/projects/virtualens/test-2-AJRWuVBy-py3.9/lib/python3.9/site-packages/anyio/_backends/_asyncio.py:756]> got Future <Future pending> attached to a different loop

There has already been a similar problem here.

Nothing has changed in the example code.

Even if I make a request not through swagger, but through the browser's query string, I still get that error. Although the query returns the data correctly.

I use:

  • python 3.9.20
  • fastapi 0.115.0
  • sse-starlette 2.1.3

Is there any way to fix this?

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

No branches or pull requests

1 participant