I have two scripts:
from fastapi import FastAPI
import asyncio
app = FastAPI()
@app.get("/")
async def root():
a = await asyncio.sleep(10)
return {'Hello': 'World',}
And second one:
from fastapi import FastAPI
import time
app = FastAPI()
@app.get("/")
def root():
a = time.sleep(10)
return {'Hello': 'World',}
Please note the second script doesn't use async
. Both scripts do the same, at first I thought, the benefit of an async
script is that it allows multiple connections at once, but when testing the second code, I was able to run multiple connections as well. The results are the same, performance is the same and I don't understand why would we use async
method. Would appreciate your explanation.