I have a question that might have a very simple answer.
Everywhere I look it says that the Django development server (manage.py runserver) is multithreaded (https://docs.djangoproject.com/en/3.2/ref/django-admin/) but this is not what I am experiencing.
DISCLAIMER: I know there are other ways to achieve this but I find this solution to be interesting and I cannot understand why it does not work.
I want to create one endpoint in my API that uses another endpoint's response to generate a report, the Views are set up as follows:
from rest_framework.views import APIView
from rest_framework.response import Response
from asgiref.sync import async_to_sync
class View1(APIView):
def get(self, request, *args, **kwargs):
response_dict = {"message": "Success!"}
return Response(response_dict)
class View2(APIView):
def get(self, request, *args, **kwargs):
client = Session()
response = self.get_response(client)
if response.get("Message") == "Success!":
return Response("Success!")
return Response("Failed!")
@async_to_sync
async def get_response(self, client):
return await client.get("http://localhost:8000/api/view1"#).json()
Now in my eyes this code looks like it should work because the request to View2 should be picked up by a first worker and the request that View2 is making to View1 should be picked up by a different worker, so that when the request to View1 is completed the request to View2 can be completed.
What I am seeing, using asgiref==3.4.1, Django==3.2.8, and djangorestframework==3.12.4 is that the request for View2 gets stuck just at the line where it makes the request to View1 and I would love to understand why that is the case.