Skip to content

Instantly share code, notes, and snippets.

@alex3165
Last active February 19, 2022 12:11
Show Gist options
  • Save alex3165/8e8a61f5ecfad24e2781bf3b54846a12 to your computer and use it in GitHub Desktop.
Save alex3165/8e8a61f5ecfad24e2781bf3b54846a12 to your computer and use it in GitHub Desktop.
import time
import asyncio
from fastapi import FastAPI
app = FastAPI()
# 1/ Request resolved in 5.03s
# 2/ Request resolved in ~10s
@app.get("/not_async")
def not_async():
time.sleep(5) # Long call to a DB or something else
return {"message": "Hello World"}
# 1/ Request resolved in 5.01s
# 2/ Request resolved in 5.02s
@app.get("/async")
async def async_endpoint():
await asyncio.sleep(5) # Long call to a DB or something else
return {"message": "Hello World"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment