0

I have a python script ["MAIN" script] that uses this line:

# Part 4, create the process and run
cmds = list()
cmds += ['python']
cmds += [script_b]
start = time.time()
p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                     shell=True)

This process,script_b start another, a third one, script_c. When i try p.kill() or p.terminate() it does not terminate script_c.
How can i terminate script_b and all its related process from the main script? Thx

Note: I use it on windows 10. This script runs both on python2.7 and 3.7 if it makes any difference.

Thx

Guy Barash
  • 470
  • 5
  • 17
  • 1
    This link will help you [Refer this](https://stackoverflow.com/questions/28551180/how-to-kill-subprocess-python-in-windows) – Ragu Natarajan Jan 22 '20 at 11:29
  • Use a Windows job object that disallows breakaway and is flagged to kill on close (of the handle). Keep the handle open to call `TerminateJobObject`. If your process crashes, this will be done automatically, so no child process will leak. – Eryk Sun Jan 22 '20 at 18:54

0 Answers0