Streaming mehrerer Videos über Fastapi in Webbrowser führt zu HTTP -Anforderungen zum StillstandPython

Python-Programme
Anonymous
 Streaming mehrerer Videos über Fastapi in Webbrowser führt zu HTTP -Anforderungen zum Stillstand

Post by Anonymous »

Ich habe eine große Fastapi -Anwendung. Es gibt viele verschiedene Endpunkte, darunter eine, die zum Proxy -Video -Streams verwendet wird. Die Verwendung ist so etwas wie folgt: Der Endpunkt empfängt die Video -Stream -URL, öffnet sie und gibt sie durch Streaming -Antwort zurück. Wenn ich 6 -Streams proxy -Streams streife, wird meine Fastapi -App nicht mehr weitere Anfragen akzeptiert, bis ich einen der geöffneten Streams im Browser schließe. < /P>
Ich muss eine viel größere Anzahl von Video Streams, aber das Problem tritt bereits auf, wenn Sie vorangetrieben. Ich werde feststellen, dass es keine Probleme mit den ursprünglichen Streams gibt, sie funktionieren direkt in jeder Menge.

Code: Select all

import uvicorn
import httpx
from fastapi import FastAPI
from fastapi.responses import StreamingResponse

app = FastAPI()

async def proxy_mjpeg_stream(url: str):

async with httpx.AsyncClient() as client:
try:
async with client.stream("GET", url) as stream:
async for chunk in stream.aiter_bytes():
if chunk:
yield chunk
except httpx.ReadTimeout as ER:
print(f'ERROR ReadTimeout - {url=} - {ER}')

@app.get("/get_stream")
async def get_stream(url: str):
if url:
headers = {
"Content-Type": 'multipart/x-mixed-replace; boundary=frame',
}
return StreamingResponse(proxy_mjpeg_stream(url), headers=headers)

if __name__ == "__main__":
uvicorn.run(app)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post