I have a script that starts an another script2.py as subprocesses. But when I close the terminal, script2.py still stays runned. How can I terminate a subprocess when closing the terminal(console).
Here is how I start the subprocess:
p = subprocess.Popen(command,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.STDOUT,
                        shell=True)
    command_output = iter(p.stdout.readline, b'')
And I normally close it like this: os.killpg(os.getpgid(p.pid), signal.SIGTERM), but how to terminate all subprocesses just by closing the console(terminal)?
