I am using subprocess.Popen
in a Django application. I then store the pid
in a database. The user can then send a rest request to /api/task/task.id/stop/
in order to kill the task.
This all works fine, except that when I kill the subprocess the Django development server is also terminated. How do I go about killing the subprocess without killing the dev server?
I start my process like this:
process = subprocess.Popen(["nohup {} {} {}".format(settings.PYTHON, "task.py", task.id) ], shell=True )
task.pid = process.pid
task.save()
And I am terminating it like this:
os.killpg( os.getpgid(task.pid), signal.SIGTERM )