0

I'm creating a task with subprocess.Popen() in Linux but if the task does not end by itself then task.kill does not kill it.

Is there a way of forcing task to end?

Right now my code looks like this:

task = subprocess.Popen(
        final_list_subprocess, stdout=subprocess.PIPE)

try:
    result, errs = task.communicate(timeout=5)
except subprocess.TimeoutExpired:
    task.kill()
except:
    task.kill()```
  • Some answers here might help: [Kill a running subprocess call](https://stackoverflow.com/questions/16866602/kill-a-running-subprocess-call) – sj95126 Oct 01 '21 at 19:35
  • This helped me: [How to terminate a python subprocess launched with shell=True](https://stackoverflow.com/questions/4789837/how-to-terminate-a-python-subprocess-launched-with-shell-true) – Tereso del Río Almajano Oct 02 '21 at 07:41

0 Answers0