Raspberry Pi:从python终止raspistill命令

2024-06-10 03:31:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在服务器上使用一个PHP文件将一些变量传输到Python脚本中,然后这个脚本将在我的Raspberry Pi上启动一个raspistill timelapse。在

到目前为止,我已经成功地开始拍照了,但是我现在想要一个按钮来关闭时间点——我已经尝试了很多方法,包括.kill()和.terminate(),但都无法正常工作。在

下面是我当前的python代码:

import sys, os, time, datetime
import subprocess
import signal
from time import sleep

tlfreq = int(sys.argv[1])
tltime = int(sys.argv[2])
dir = '/var/www/timelapse/' + sys.argv[3]

if not os.path.exists(dir):
    os.makedirs(dir)

cmd = ('raspistill -t ' + str(tltime) + " -tl " + str(tlfreq) + " -o " + dir + "/photo_%04d.jpg")
pro = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                   shell=True, preexec_fn=os.setsid)
print "Pictures are now being taken every" , tlfreq/1000 , "second/s for a total of", tltime/3600000 , "hours. These are being stored in", dir

也许我需要一个“if variable=1 then kill”命令,然后将变量发送给python。在

任何帮助将不胜感激!在

非常感谢, 丹


Tags: import脚本iftimeosdirsysint