-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Open
Description
StreamingResponse docs state:
Takes an async generator or a normal generator/iterator
However based on Kludex/starlette#1776 (comment) async generetors need something awaited to work:
import asyncio
from time import sleep
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
app = FastAPI()
async def fake_video_streamer():
for i in range(10):
sleep(0.1)
yield b"some fake video bytes"
# await asyncio.sleep(0) # <-- uncomment to fix example
@app.get("/")
async def main():
"""
this is as per
https://fastapi.tiangolo.com/advanced/custom-response/?h=responses#streamingresponse
but does not to work (blocks for 1 sec, then returns all chunks at once):
curl -sNo- localhost:8000
wget -qO- localhost:8000
"""
return StreamingResponse(fake_video_streamer())uvicorn==0.40.0fastapi==0.128.0
Metadata
Metadata
Assignees
Labels
No labels