在python中杀死子进程

时间:2018-02-28 16:56:20

标签: python

在我的python脚本中,我需要用一个进程启动一个shell,我喜欢以下内容:

cmd = "x-terminal-emulator -e mytask"
self.task = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)

这将打开一个进程运行的终端。

此过程持续运行。在某些时候,我想杀死这个过程,我尝试这样做:

if self.jlink != None:
    print "Stopping", str(self.task.pid)
    self.task.kill()
else:
    print "Process doesn't exist"

问题在于,即使打印出Stoppping ...消息,也不会杀死该进程。

我错过了什么吗?

0 个答案:

没有答案
相关问题