0

In views, I have a process that takes a few seconds to compute. As it stands, this process comes before my view function returns a next webpage. However, it is not crucial that this process runs before, and in fact it can run anytime. Therefore, I am wondering if it is possible to run this process, and then return the next webpage before the process has finished. I suppose this would be considered multi-threading.

For example:

def myViewFunction(request):
    myProcess() # This takes a while to finish
    return render(request, 'myapp/mywebpage.html')

Can I run myProcess() in the background, and return render() as soon as myProcess() has been called, rather than wait until it has returned?

Karnivaurus
  • 18,315
  • 44
  • 129
  • 209

1 Answers1

1

What you are looking for is Celery. See this answer for an example of using Celery inside Django.

Community
  • 1
  • 1
dukebody
  • 6,284
  • 3
  • 30
  • 54