You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running a FastAPI app with uvicorn default settings (--loop auto, which uses uvloop when installed), I started to notice that sometimes when handling multiple requests for the same path the response took longer than expected to arrive at the client. This issue became more noticeable when I tried using WebSockets to improve performance by returning the result in parts over the same connection instead of making multiple HTTP requests.
The issue is with uvloop itself, not with uvicorn. I don't know why, but it looks like uvloop is not switching tasks properly... If you do await anyio.sleep(0) it will force the event loop to switch tasks, and then you can have the behavior you want.
Please open an issue with a MRE on uvloop. This MRE was too big for uvicorn itself.
Initial Checks
Discussion Link
I am opening the issue because another user commented on the opened discussion thread, and no maintainer interacted with the thread.
Description
When running a FastAPI app with uvicorn default settings (--loop auto, which uses uvloop when installed), I started to notice that sometimes when handling multiple requests for the same path the response took longer than expected to arrive at the client. This issue became more noticeable when I tried using WebSockets to improve performance by returning the result in parts over the same connection instead of making multiple HTTP requests.
See discussion for more details.
Is this behavior expected when using the default event loop?
Example Code
FastAPI App Code
HTTP Client Code
WebSocket Client Code
Python, Uvicorn & OS Version
The text was updated successfully, but these errors were encountered: