Page 1 of 1

FastAPI führt API-Aufrufe seriell statt parallel aus

Posted: 03 Jan 2025, 14:01
by Guest
Ich habe den folgenden Code:

Code: Select all

from fastapi import FastAPI, Request
import time

app = FastAPI()

@app.get("/ping")
async def ping(request: Request):
print("Hello")
time.sleep(5)
print("bye")
return {"ping": "pong!"}
Wenn ich meinen Code auf localhost ausführe – z. B. http://localhost:8501/ping – in verschiedenen Registerkarten desselben Browserfensters, erhalte ich Folgendes:

Code: Select all

Hello
bye
Hello
bye
statt:

Code: Select all

Hello
Hello
bye
bye
Ich habe über die Verwendung von httpx gelesen, aber ich kann immer noch keine echte Parallelisierung erreichen. Was ist das Problem?