-
|
So, I think I understand all If I visit However if I open two requests to I want to know why is that the case and if this is the default behaviour where requests to different endpoints run in different threads but requests to the same endpoint run one after the other. I also wonder if there is a way to make the requests to the same endpoint run in different threads and |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
|
time.sleep should be async (which is not) and you should await for it |
Beta Was this translation helpful? Give feedback.
-
I am using normal |
Beta Was this translation helpful? Give feedback.
-
|
I can't reproduce your behavior. It works just fine here. |
Beta Was this translation helpful? Give feedback.
-
apparently no |
Beta Was this translation helpful? Give feedback.
-
Care to elaborate? Or where I am wrong ? |
Beta Was this translation helpful? Give feedback.
-
|
@nilansaha How are you performing the requests? I found some time ago that (some) browsers (Firefox in my case) seem to avoid performing simultaneous requests to the same endpoint (or localhost?). Maybe try this code to perform N concurrent requests using Python, I'd say your example would work as expected after trying it: import threading
import requests
N_REQUESTS = 5
def req():
requests.get("http://localhost:8000/hi")
threads = [threading.Thread(target=req, daemon=True) for _ in range(N_REQUESTS)]
[th.start() for th in threads]
[th.join() for th in threads]Output from fastapi server: |
Beta Was this translation helpful? Give feedback.
-
|
Indeed that is the case. Chrome was not allowing to run another request on same endpoint until the first one is finished. And thats why the confusion. |
Beta Was this translation helpful? Give feedback.
@nilansaha How are you performing the requests? I found some time ago that (some) browsers (Firefox in my case) seem to avoid performing simultaneous requests to the same endpoint (or localhost?).
Maybe try this code to perform N concurrent requests using Python, I'd say your example would work as expected after trying it:
Output from fastapi server: