From 9a3d2470eb72189ff8ddb62d2e630bb54e10b45a Mon Sep 17 00:00:00 2001 From: bBlazewavE <260532195+bBlazewavE@users.noreply.github.com> Date: Tue, 10 Feb 2026 10:27:10 -0300 Subject: [PATCH] fix: use await asyncio.sleep() in StreamingResponse async generator example The async generator in the StreamingResponse docs example did not await anything, causing all chunks to be returned at once instead of streaming. Added await asyncio.sleep(0) so the event loop can yield between chunks, enabling proper streaming behavior. Closes #14680 --- docs_src/custom_response/tutorial007_py39.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs_src/custom_response/tutorial007_py39.py b/docs_src/custom_response/tutorial007_py39.py index e2a53a2119..0c17ce40ee 100644 --- a/docs_src/custom_response/tutorial007_py39.py +++ b/docs_src/custom_response/tutorial007_py39.py @@ -1,3 +1,5 @@ +import asyncio + from fastapi import FastAPI from fastapi.responses import StreamingResponse @@ -6,6 +8,7 @@ app = FastAPI() async def fake_video_streamer(): for i in range(10): + await asyncio.sleep(0) yield b"some fake video bytes"