如何在Python中终止我的子进程

时间:2015-05-06 17:19:44

标签: python raspberry-pi subprocess

我有两个子流程,如下所示

cmd1='arecord -d 0 -f cd -t wav test.wav'
cmd2='raspivid -o video.h264 -fps 25 -t 0'

pro1 = subprocess.Popen(cmd1, shell=True)
pro2 = subprocess.Popen(cmd2, shell=True)

我想用raspberry pi同时录制音频和视频。从现在开始,我可以启动这两个程序,但我无法阻止这些程序。有人能帮助我吗?

或者通过简单的方式做这个过程的任何想法?

2 个答案:

答案 0 :(得分:2)

来自文档:

  

Popen.terminate()阻止孩子。在Posix操作系统上,该方法发送   SIGTERM给孩子。在Windows上Win32 API函数   调用TerminateProcess()来阻止子进程。

     

2.6版中的新功能。

     

Popen.kill()杀死孩子。在Posix OS上,该函数发送SIGKILL   对孩子。在Windows上,kill()是terminate()的别名。

答案 1 :(得分:0)

Python's subprocess module的文档包含Popen.terminate()Popen.kill()的说明。

相关问题