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