I have a script
import os
os.system('python manage.py runserver')
The script starts django server (no matter what it does, it can be any command which evaluates until ctrl+c
or another key shortcut is pressed).
What I want is to stop the server by any way but not by killing it by pid.
What I've tried:
I tried to use subprocess
lib and it's kill
command as described here: How to terminate a python subprocess launched with shell=True
But it does not help. As I guess, the reason is: we are killing not the manage.py runserver
process but the process which evaluates python manage.py runserver
. So, after killing process, server is still running.
Also I've tried use terminate
method:
p = subprocess.Popen('python manage.py runserver', stdout=subprocess.PIPE, shell=True)
time.sleep(5)
p.terminate()
As I think it should work this way: server starts and after 5 seconds it stops, but it never stops.
Is there any way to kill the process?