[QUESTION] Would expect this simple example to behave asynchronously but it doesn't
See original GitHub issueDescription
I’m probably not understanding the asynchronous concept correctly in FastAPI.
I’m accessing the root endpoint of the following app from two clients at the same time. I’d expect FastAPI to print Started
twice:
from fastapi import FastAPI
import asyncio
app = FastAPI()
@app.get("/")
async def read_root():
print('Started')
await asyncio.sleep(5)
print('Finished')
return {"Hello": "World"}
Instead I get the following, which looks very much non asynchronous:
Started
Finished
INFO: ('127.0.0.1', 49655) - "GET / HTTP/1.1" 200
Started
Finished
INFO: ('127.0.0.1', 49655) - "GET / HTTP/1.1" 200
What am I missing?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Async function not behaving as I expect with Jest
Async function not behaving as I expect with Jest · 1. If you don't pass done as an argument the code is considered...
Read more >Error thrown - Warning: You called act(async () => ...) without ...
I have a simple test that seems to generate the right snapshot at the end of execution, but throws me a console.error during...
Read more >When to Use (and Not to Use) Asynchronous Programming
Asynchronous programming is a form of parallel programming that allows a unit of work to run separately from the primary application thread.
Read more >Async/await - The Modern JavaScript Tutorial
The word “async” before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved...
Read more >Introduction to Asynchronous JavaScript - Pluralsight
In this free JavaScript tutorial, we'll explain the difference between synchronous and asynchronous Javascript and the difficulties of using ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
sorry misread you explain what you want and you’re right it should do that
I guess when you state that you used 2 clients at the same time, maybe that was not enough at the same time, no idea how you proceeded to launch concurrent requests
See this log launching 10 concurrent requests with
ab -n 10 -c 10 http://localhost:8000/
snippet used
Thanks for the help here @euri10 ! 👏 🙇
Thanks for reporting back and closing the issue @fhennecker 👍