0

I have checked most of the comments and the answer always was that Django (on local machine) handles only one request at a time. I have simple django application with view function that waits 5 seconds. When I run two the same GET requests in postman, I can see both requests are handled in the same time, they are not queued or overwritten one by another. My question is how it is possible?

My view code:

def wait_some_time(request):

    import time
    print("Printed immediately.")
    time.sleep(5)
    print("Printed after 5 seconds.")

    return Response({'message': 'nothing'})

Postman request: Postman request (I'm sending 2 requests in the same time)

Console output:

Printed immediately.
Printed immediately.
Printed after 5 seconds.
[05/Jan/2022 14:55:35] "GET /api/user/test HTTP/1.1" 200 21
Printed after 5 seconds.
[05/Jan/2022 14:55:36] "GET /api/user/test HTTP/1.1" 200 21
Quishu
  • 1
  • 4
  • Where did you get the idea that the dev server only handles one request at a time? It's multithreaded by default https://docs.djangoproject.com/en/4.0/ref/django-admin/#cmdoption-runserver-nothreading – Iain Shelvington Jan 05 '22 at 14:07
  • From this answer: https://stackoverflow.com/a/49214051/6579746 You are completly right, thanks for your answer, I couldn't find information about that. `The server is multithreaded by default.` – Quishu Jan 05 '22 at 14:14
  • hi, i'm not sure what you are trying to achieve but it seems that you may not be testing what you are looking for correctly. Each request is handled separately and so the output you are getting is correct for 2 separate requests, each request will print immediately and after 5 seconds. Could you explain what it is you're actually trying to achieve? – caleo Jan 05 '22 at 14:17
  • @caleo I was wondering if django uses only one thread, but results and IainShelvington comment prove it launches other threads if needed. – Quishu Jan 05 '22 at 17:00

0 Answers0