Raspberry Pi: terminate raspistill command from python

I'm trying to use a PHP file on a server to transmit some variables into a Python script which will in turn start a raspistill timelapse on my Raspberry Pi.

I've so far managed to start taking pictures but I'd now like to have a button to kill the timelapse - i've tried many methods including .kill() and .terminate() but cant get it working.

Here is my current python code:

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

Perhaps I need an "if variable = 1 then kill" command and then send the variable to python.

Any help would be greatly appreciated!

Many thanks, Dan


You can create new python script kill_raspystill.py with this code

import os

os.system("pkill raspistill")

and call that script when you press a button.


我会建议信号库:http://docs.python.org/2/library/signal.html

链接地址: http://www.djcxy.com/p/77154.html

上一篇: 在拍摄照片时预览fswebcam图像

下一篇: Raspberry Pi:终止来自python的raspistill命令