2

I am using this code to read logs from mobile device:

with subprocess.Popen(read_device_logs_cmd, shell=True, stdout=subprocess.PIPE, bufsize=1,
                              universal_newlines=True, errors="replace") as p:

    for line in p.stdout:
        save(line)

So p will be running endlessly. Edit: and important info, this subprocess is running in Thread so I can manipulate loop inside of subprocess from other part of code.

How can I correctly stop p programatically?

In terminal I'd just have to do CTRL + C.

Will p.kill() or p.terminate() do the job?

F1sher
  • 7,140
  • 11
  • 48
  • 85

1 Answers1

2

You can use p.kill() to kill a subprocess.

Emil Rowland
  • 538
  • 5
  • 25