终止正在运行的进程

时间:2016-02-02 17:22:04

标签: windows python-2.7 64-bit kill-process taskkill

我有以下代码,它运行几个命令行应用程序。如果我然后尝试杀死进程,有时它会工作,有时它不会,并且进程继续运行。 我只是想检查一下我所做的是否是正确的首选方法? 我在Windows 7和Windows Server 2012,Python 2.7.11上运行,全部是64位。

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
environ1 = os.environ.copy()
environ1['FFREPORT'] = 'level=32:file={}'.format(ffmpeglogFilePath)
self.ffmpeglogFilePath1 = ffmpeglogFilePath
self.process1a = Popen(command1, stdout=PIPE, startupinfo=startupinfo)
self.process1b = Popen(command2, stdin=self.process1a.stdout, startupinfo=startupinfo, env=environ1)


def killProcess1(self, running_pane1):
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    Popen("TASKKILL /F /PID {pid} /T".format(pid=self.process1a.pid), startupinfo=startupinfo)
    Popen("TASKKILL /F /PID {pid} /T".format(pid=self.process1b.pid), startupinfo=startupinfo)

0 个答案:

没有答案