How to terminate a python subprocess launched with shell=True

前端 未结 12 2707
轮回少年
轮回少年 2020-11-21 04:53

I\'m launching a subprocess with the following command:

p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)

However, when I try t

12条回答
  •  梦毁少年i
    2020-11-21 05:18

    Send the signal to all the processes in group

        self.proc = Popen(commands, 
                stdout=PIPE, 
                stderr=STDOUT, 
                universal_newlines=True, 
                preexec_fn=os.setsid)
    
        os.killpg(os.getpgid(self.proc.pid), signal.SIGHUP)
        os.killpg(os.getpgid(self.proc.pid), signal.SIGTERM)
    

提交回复
热议问题