How use ProcessPoolExecutor in django?

153 Views Asked by At

In a Django Project I want to use ProcessPoolExecutor but I can do that. Is there any solution? I call a function in view that has executor.

I use Django==4.1.7.

what should add to my function to run in django. The start() function works properly outside django. but doesn't work in django.

from a views.py in django app call a function that contain executor:

def start():
     #'... some code here'

     with concurrent.futures.ProcessPoolExecutor(max_workers=num_procs) as executor:
1

There are 1 best solutions below

0
On

I recommend using Celery for calling out asynchronous tasks from Django. This way you will also have a way of tracking the process & possible errors. It takes a little to get to know the logic, but it's worth it.

https://docs.celeryq.dev/en/stable/index.html

https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html