[Python] FastAPI runs api-calls in serial instead of parallel fashion

Discussão em 'Python' iniciado por Stack, Dezembro 9, 2024.

  1. Stack

    Stack Membro Participativo

    I have the following code:

    import time
    from fastapi import FastAPI, Request

    app = FastAPI()

    @app.get("/ping")
    async def ping(request: Request):
    print("Hello")
    time.sleep(5)
    print("bye")
    return {"ping": "pong!"}


    If I run my code on localhost—e.g., http://localhost:8501/ping—in different tabs of the same browser window, I get:

    Hello
    bye
    Hello
    bye


    instead of:

    Hello
    Hello
    bye
    bye


    I have read about using httpx, but, still, I cannot have a true parallelization. What's the problem?

    Continue reading...

Compartilhe esta Página