I use a script to run two script. the code like this:
import subprocess
subprocess.Popen("python a.py", shell=True)
subprocess.Popen("python b.py", shell=True)
but if I end the main script, the sub process of a.py and b.py are still runing. How to solve it?
added:
the a.py and b.py is two server scripts. When I end the main script using ctrl+c,and the two servers is not end up.So how to end the all process when I end the main script?
shell=True, you are only introducing a security risk with that. Just doPopen(['python', 'a.py']).shell=Trueis useful only when you are using some shell feature (e.g. pipes/redirection/built-ins/expansions etc) and even most of those can actually be avoided. If you are just running an executable do not specifyshell=True.import a.pyor at leastcompileandexec?Popen(["python", "a.py"])notPopen("python a.py"). Or if you don't want to manually write the least do :import shlexand thenPopen(shlex.split("python a.py")))