What I need to do is run a process that might take hours to complete from a Django view. I don't need to the state or communicate with it but I need that view to redirect away right after starting the process.
I've tried using subprocess.Popen
, using it within a new threading.Thread
, multiprocessing.Process
- parent process keeps hanging until child terminates. The only way that almost gets it done is using a fork. But that obviously isn't good as it leaves a zombie process behind until parent terminates.
That's what I'm trying to do when using fork:
if os.fork() == 0:
subprocess.Popen(["/usr/bin/python", script_path, "-v"])
else:
return HttpResponseRedirect(reverse('view_to_redirect'))
So, is there a way to run completely independent process from a Django view with minimal casualties? Or am I doing something wrong?