Sure, you want to call Popen.terminate()
or Popen.kill()
on the subprocess. e.g.:
p = subprocess.Popen(['path/to/long/runnning/process', 'arg1', 'arg2'])
...
p.terminate() # kill the process.
Popen.terminate
is a little more gentle -- On POSIX OSs, it'll give the program a chance to handle the signal and do some cleanup vs. kill
which will try to destroy the process immediately.