Browse Source
Add `await asyncio.sleep(0)` to the async generator in the StreamingResponse documentation example so it properly yields control back to the event loop between iterations, enabling true incremental streaming and proper task cancellation. Without an await point the async generator holds the event loop for the entire iteration, buffering the full response before sending it to the client. Also add a note admonition explaining why the await is needed and suggesting sync generators as an alternative when there are no natural await points. Closes #14680pull/14993/head
2 changed files with 16 additions and 1 deletions
Loading…
Reference in new issue