Browse Source

📝 Fix StreamingResponse doc example to actually stream

Add `await asyncio.sleep(1)` to the async generator example so it
yields control back to the event loop between chunks, demonstrating
actual streaming behavior instead of returning all chunks at once.

Closes #14680
pull/14886/head
DM 5 months ago
parent
commit
64a09ef251
  1. 3
      docs_src/custom_response/tutorial007_py39.py

3
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(1)
yield b"some fake video bytes"

Loading…
Cancel
Save