I have a script a.py
This scripts calls b.py which is a similar script which calls c.py which calls d.py. I am trying to simulate a condition that if b encounters a timeout I should kill b and all the child process it spawns, When I use the killpg api I see all the process killed including a.py, also I tried to use os.kill but it only kills b.by. Is there a way to kill b.py and all the processes it spawns but not kill a.py?
I am using python 2.7.12
#!/usr/bin/python -t
import time
import subprocess
import os
import signal
cmd = "./b.py"
p = subprocess.Popen(cmd, shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
time.sleep(30)
#os.kill(p.pid, signal.SIGKILL)
os.killpg(os.getpgid(p.pid), signal.SIGTERM)