您可以将cron用于简单任务。
为您的任务创建一个烧瓶视图。
# a separate view for periodic task
@app.route('/task')
def task():
board.read()
board.digital_outputs = board.digital_inputs
然后使用cron,定期从该网址下载
# cron task to run each minute
0-59 * * * * run_task.sh
run_task.sh的内容在哪里
wget http://localhost/task
Cron无法每分钟运行一次以上。如果需要更高的频率(例如,每5秒=每分钟12次),则必须按以下方式在tun_task.sh中进行操作
# loop 12 times with a delay
for i in 1 2 3 4 5 6 7 8 9 10 11 12
do
# download url in background for not to affect delay interval much
wget -b http://localhost/task
sleep 5s
done