Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
终止子进程将退出Python程序_Python_Tkinter_Subprocess - Fatal编程技术网

终止子进程将退出Python程序

终止子进程将退出Python程序,python,tkinter,subprocess,Python,Tkinter,Subprocess,当我按下按钮(使用TK库创建)时,会调用此函数。3秒钟后,我的整个程序(连同GUI屏幕)被终止,而不仅仅是子进程。我如何纠正这一点,并确保只有子流程proc1被终止 如果您阅读了的文档,有几种方法可供选择: 发送信号(信号) 向孩子发送信号 在Windows上,SIGTERM是terminate()的别名 Popen.terminate() 阻止孩子。在Posix OSs上,该方法将SIGTERM发送给子级。在Windows上,调用Win32 API函数TerminateProcess()来停止

当我按下按钮(使用TK库创建)时,会调用此函数。3秒钟后,我的整个程序(连同GUI屏幕)被终止,而不仅仅是子进程。我如何纠正这一点,并确保只有子流程proc1被终止

如果您阅读了的文档,有几种方法可供选择:

发送信号(信号)

向孩子发送信号

在Windows上,SIGTERM是terminate()的别名

Popen.terminate()

阻止孩子。在Posix OSs上,该方法将SIGTERM发送给子级。在Windows上,调用Win32 API函数TerminateProcess()来停止子进程

Popen.kill()

杀死孩子。在Posix OSs上,函数将SIGKILL发送给子级。在Windows上kill()是terminate()的别名

我将使用:

def playvid(self):
    proc1 = subprocess.Popen("gst-launch-1.0 videotestsrc ! autovideosink", shell=True)
    time.sleep(3)
    os.killpg(os.getpgid(proc1.pid),signal.SIGTERM)

从doc:os.getpgid(pid)返回进程id为pid的进程的进程组id。如果pid为0,则返回当前进程的进程组id。如何单独终止特定子进程?
proc1.terminate()