I need to stop a process created using subprocess.call
in Python when I get a Keyboard Interrupt (ctrl-c)
The issue is p doesn't get a value assigned to it till it finishes execution
p = subprocess.call(cmd)
So I cant use os.kill
to kill that. Also, can't use shell=True
because reasons.
What I would like to do is :
try:
p = subprocess.call(cmd)
except KeyboardInterrupt:
os.kill(p.pid,signal.SIGTERM)
sys.exit('exited after ctrl-c')