Making sure a Python script with subprocesses dies on SIGINT

前端 未结 5 887
感动是毒
感动是毒 2020-12-29 18:36

I\'ve got a command that I\'m wrapping in script and spawning from a Python script using subprocess.Popen. I\'m trying to make sure it dies if the

5条回答
  •  失恋的感觉
    2020-12-29 19:21

    If you have no python processing to do after your process is spawned (like in your example), then the easiest way is to use os.execvp instead of the subprocess module. Your subprocess is going to completely replace your python process, and will be the one catching SIGINT directly.

提交回复
热议问题