stop a subprocess python

Solutions on MaxInterview for stop a subprocess python by the best coders in the world

showing results for - "stop a subprocess python"
Effie
12 Jan 2020
1import os
2import signal
3import subprocess
4
5# The os.setsid() is passed in the argument preexec_fn so
6# it's run after the fork() and before  exec() to run the shell.
7pro = subprocess.Popen(cmd, stdout=subprocess.PIPE, 
8                       shell=True, preexec_fn=os.setsid) 
9
10os.killpg(os.getpgid(pro.pid), signal.SIGTERM)  # Send the signal to all the process groups
11