蟒子,杀时间延迟后处理 [英] Python subprocess, kill process after timed delay
问题描述
我与Python和树莓派工作第一次(这是一个丕2),并试图控制定时的命令集。我已经得到了大部分想出除了尽头,在这里我要杀死所有进程。
I'm working with Python and Raspberry Pi for the first time (it's a Pi 2) and trying to trigger a timed set of commands. I've got most of it figured out except the very end, where I want to kill all processes.
的逻辑如下:
- 触发的音频文件(.wav)所谓的倒计时
-- Trigger an audio file (.wav) called "countdown"
- 引发另一音频文件(.wav)称为迪克西
-- Trigger another audio file (.wav) called "dixie"
- 虽然迪克西正在播放一个触发的wget命令触发我的相机上的照片
-- While dixie is playing trigger a wget command to trigger a photo on my camera
- 继续玩迪克西,直到previous wget的完成执行
-- Keep playing "dixie" until the previous wget finishes executing
- 当wget的完成执行,停止播放迪克西
-- When wget finishes executing, stop playing "dixie"
- 触发最后的音频文件(.wav)所谓的掌声
-- Trigger final audio file (.wav) called "applause"
- 停止所有音频
从本质上讲,wget的是最重要的,音频文件播放只是,而我的相机拍摄的照片来创作音乐。当wget的完成和掌声结束,我要杀死所有的音频,但对于迪克西的subprocess.Popen命令继续播放(这是约40秒之久)。我怎么能在最后杀死这个过程吗?
Essentially, the wget is the important one, the audio files playing are just to create music while my camera takes a photo. When the wget has finished, and the applause finishes, I want to kill all the audio, but the subprocess.Popen command for "dixie" continues to play (it's about 40 seconds long). How can I kill this process at the end?
下面是我的code迄今:
Here is my code so far:
import os
import time
import subprocess
subprocess.call(["aplay countdown.wav"], shell=True)
subprocess.Popen(["aplay dixie.wav"], shell=True)
subprocess.call(["wget 'http://10.5.5.9/camera/SH?t=12345678&p=%01' -O-"], shell=True)
time.sleep(5)
subprocess.call(["aplay applause.wav"], shell=True)
subprocess.Popen.kill(["aplay dixie.wav"], shell=True)
我要杀人迪克西曾经叫好播放完毕。
I want to kill "dixie" once "applause" has finished playing.
我的code产生的错误:
My code yields the error:
"unbound method kill() must be called with Popen instance as first
argument (got list instance instead)"
任何建议了吗?
推荐答案
我建议这样做的:
proc = subprocess.Popen(["aplay dixie.wav"], shell=True)
# do something
proc.terminate()
这篇关于蟒子,杀时间延迟后处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!