I run 20 subprocesses by using:
process1 = subprocess.Popen(command1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
shell=False, encoding='utf-8', cwd=full_path)
command1 is calling a file named: "scheduleInstasck.py" which triggers also another command:
process2 = subprocess.Popen(command2, shell=False, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, cwd='./{}'.format(client_folders[running_index]))
command2 is calling a file named: "quickstart.py" which is my app.
Once I call process1.terminate() it will only kill process1 while process2 is still alive and I see all logs of it until it finish.
I did try:
https://stackoverflow.com/a/320712/4215840
https://stackoverflow.com/a/31464349/4215840
to catch termination on scheduleInstasck and to do process2.terminate() but this never called for some reason on Windows.
For some long-term results I would suggest better indexing and overall process/memory management. An easy solution however, would just to iterate the active child processes of whatever process you are about to kill.
multiprocessing.active_childrenis probably what you would want to use. You can also reference this answer