How to terminate a subprocess in Python

Terminating a subprocess stops the subprocess by sending a SEGTERM signal to it.

Solution for How to terminate a subprocess in Python : You can use subprocess.Popen.terminate() to terminate a subprocess Call subprocess.Popen(args) with args as a sequence of program arguments or a single string to execute a child program in a new process with the supplied arguments. To terminate the subprocess, call subprocess.Popen.terminate() with subprocess.Popen as the result from the previous step.

To check if a child process has terminated, call subprocess.Popen.poll() with subprocess.Popen as the child process. If a None value is returned it indicates that the process hasn’t terminated yet.


how-to-terminate-a-subprocess-in-python