'Django: calling a function and let it run in different thread with out waiting and affecting the main thread

I'm trying to work out how to run a process in a background thread in Django.

Here is a api view which gets called by user and i need that (Crawler.crawl(request.user)) function to run independently and complete the work. User hitting this api view will not have to wait or the request time out will also not be an issue.

class CrawlApiView(APIView): permission_classes = [IsAdminUser, ]

def get(self, request, format=None):
    Crawler.crawl(request.user)
    response = {
        "Crawl has Started ",
    }
    return Response(response, status=status.HTTP_201_CREATED)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source