Py学习  »  Python

带有子进程的Cronie-python不运行

Alex • 6 年前 • 933 次点击  

我已经建立了亲信( https://github.com/cronie-crond/cronie )变成一个yocto图像,如下所示 /etc/crontab :

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

#  m  h  dom mon dow user   command
#  1  *     * * *    root        cd / && run-parts /etc/cron.hourly
# 30  7     * * *    root        cd / && run-parts /etc/cron.daily
# 42  7     * * 7    root        cd / && run-parts /etc/cron.weekly
# 55  7     1 * *    root        cd / && run-parts /etc/cron.monthly
*/2 * * * * foo /usr/bin/python3 /home/foo/code/heartbeat.py && /usr/bin/python3 /home/foo/code/amplitude.py

心跳正常,但振幅不正常。振幅涉及python调用子进程:

import subprocess
import numpy
import wavio

from base_reading import publishReading

try:
    subprocess.run(['/usr/bin/arecord', '-D', 'plughw:0', '-c1', '-r', '48000', '-f', 'S32_LE', '-t', 'wav', '-d', '10', '-V', 'mono', '-v', '/tmp/file.wav'])
except:
    subprocess.run(['/usr/bin/arecord', '-D', 'plughw:1', '-c1', '-r', '48000', '-f', 'S32_LE', '-t', 'wav', '-d', '10', '-V', 'mono', '-v', '/tmp/file.wav'])

source = "/tmp/file.wav"

file = wavio.read(source).data

amplitude = numpy.mean(file)
stddev = numpy.std(file)

subprocess.run(['rm', '/tmp/file.wav'])

publishReading({'sensor_type': 'noise', 'mean': amplitude, 'stddev': stddev})

我在谷歌上搜索了很多,总的结论似乎是对我拥有的所有东西都使用绝对路径,但仍然行不通。 fwiw,heartbeat(没有子进程)甚至可以在python的相对路径下完美工作。

奇怪的是,日志文件似乎不存在,这可能是YOCTO的东西(它是基于BuyBox,我想)。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/48392