Forums

Run a background task in Django 4 and python 3.8

Hi, I have a Django rest framework view that calls a function that takes 30-40 seconds and then returns a response. Since it is used to send SMS to 60,000 people there is no way we can reduce the time. So I want that function to run in the background and the view shouldn't wait for the function to get over. I don't want to use celery and I think threads can't be used with pythonanywhere. here's the sample code.

class MyAPIView(APIView):
  def get(self, request, *args, **kwargs):
      function_that_takes_40_secons_to_executes()
      return Response("bulk SMS sent")

So i want this function call to run in background, when deployed on pythonanywhere.

Take a look at https://blog.pythonanywhere.com/198/