1

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.

Si si
  • 317
  • 1
  • 6

1 Answers1

0

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_children is probably what you would want to use. You can also reference this answer

coffee
  • 159
  • 1
  • 5
  • So issues is mostly due to using subprocess ? – Sion C May 18 '23 at 05:56
  • I will implement a web server bit that will hold the status of running, idle, stop_req this is the only way I can find now working, morevover it will be easy to distribute the system later. – Si si May 18 '23 at 14:48