python - 树莓派 : terminate raspistill command from python

标签 python linux subprocess raspberry-pi

到目前为止,我已经设法开始拍照,但我现在想要一个按钮来终止游戏中时光倒流——我已经尝试了很多方法,包括 .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。

如有任何帮助,我们将不胜感激!

非常感谢, 丹

最佳答案

您可以使用此代码创建新的 python 脚本 kill_raspystill.py

import os

os.system("pkill raspistill")

并在您按下按钮时调用该脚本。

关于python - 树莓派 : terminate raspistill command from python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18825899/

相关文章:

linux - 共享库标准使标志可变吗?

linux - 压缩文件夹的内容包括父目录

python - 获取特定 channel 的所有用户 Slack API

python - Pandas SparseDtype 不适用于 GroupBy

Enthought Canopy 中的 Python 文件 open() 失败并显示 : "IOError No such file or directory"

PHP $_SERVER [‘SERVER_ADDR’ ] 变量总是返回 127.0.0.1

python - 在继续之前如何/最好的方式等待 Mongod 实例启动

python - 如何获取子进程的 stderr 流输出的最后 N 行?

python - 停止进程 pygtk

python - 在python中查找两个文件之间的差异