kill subprocess when python process is killed?

后端 未结 3 531
自闭症患者
自闭症患者 2021-01-05 17:17

I am writing a python program that lauches a subprocess (using Popen). I am reading stdout of the subprocess, doing some filtering, and writing to stdout of main process.

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-05 18:08

    subprocess.Popen objects come with a kill and a terminate method (differs in which signal you send to the process).

    signal.signal allows you install signal handlers, in which you can call the child's kill method.

提交回复
热议问题