kill subprocess when python process is killed?

后端 未结 3 566
自闭症患者
自闭症患者 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:02

    You can use python atexit module.

    For example:

    import atexit
    
    def killSubprocess():
        mySubprocess.kill()
    
    atexit.register(killSubprocess)
    

提交回复
热议问题