Last active
February 19, 2022 12:11
-
-
Save alex3165/8e8a61f5ecfad24e2781bf3b54846a12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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