Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
FastAPI parallel requests not working in Python
from fastapi import FastAPI
import uvicorn
app = FastAPI()

#Some long processing code, with async declaration
async def doBTask():
    print ("Request started")
    #asyncio.sleep(20)
    sum = 0
    for n in range (1, 10000):
        for m in range(1,10000):
            if m%n ==0:
                pass
            else:
                sum = sum + n    
    
    print ("Completed")
    return sum


@app.get("/")
async def read_root():
    result = await doBTask()
    
    return {"Result": result}

uvicorn.run(app, host="0.0.0.0", port=7000)

When we call that URL in different tabs, the output is coming one after another (even print also). It is clearly single processing but not parallel request processing. Can someone guide where is the mistake, and why FastAPI with async and await not working?

Edit Here is the response I am getting if tried in different browsers and dummy params (you can see, it is processing one after another, even though I sent all at a time)

Request started
Completed
INFO:     127.0.0.1:58998 - "GET /?n=10 HTTP/1.1" 200 OK
Request started
Completed
INFO:     127.0.0.1:59012 - "GET /?m=30 HTTP/1.1" 200 OK
Request started
Completed
INFO:     127.0.0.1:59288 - "GET / HTTP/1.1" 200 OK
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda