在另一个函数中终止Python中的子进程?

在另一个函数中终止Python中的子进程?,python,ubuntu,subprocess,kill,Python,Ubuntu,Subprocess,Kill,我是Python新手。这是我的代码: def start(self, widget): s = subprocess.Popen('myprocess') def stop(self, widget): #what to put here? 我在Ubuntu上。在第一个函数中,我启动一个进程,该进程需要CTRL+C来终止。我必须在停止功能中输入哪些指令才能终止流程 事先非常感谢。我只是用一个全局变量s来求解。所以我的代码变成: s = None def s

我是Python新手。这是我的代码:

def start(self, widget):
    s = subprocess.Popen('myprocess')

def stop(self, widget):
           #what to put here?
我在Ubuntu上。在第一个函数中,我启动一个进程,该进程需要CTRL+C来终止。我必须在停止功能中输入哪些指令才能终止流程


事先非常感谢。

我只是用一个全局变量s来求解。所以我的代码变成:

 s = None

 def start(self, widget):
       global s
       s = subprocess.Popen('myprocess')

 def stop(self, widget):
       s.kill()
更好:def start_processself,dummy:if self.myprocess:self.stop_processdummy\n self.myprocess=Popen'myprocess'和def stop_processself,widget:p,self.myprocess=self.myprocess,无;p、 终止;widget.after5000,kill_进程,p;