以 SystemD 启动的 Python 程序无法找到临时文件

问题描述

我有一个关于从 const app = express(); const router = express.Router(); router.get('/',getPosts); router.post('/',createPost); app.use('/',router) export default router; 启动的 Python (3) 程序中得到的有趣错误的问题。这一切都发生在运行完全更新的 Raspberry Pi OS 的 Raspberry Pi Zero 上。它是 Google AIY Voice Kit v2 的大脑,尽管在这里似乎并不是很重要。

有问题的 systemd 服务运行我的 Python 程序,该程序调用 systemd。但是,这会返回一个 aiy.voice.tts.say("Example text") - 完整的回溯是:

FileNotFoundError

从这个回溯中可以清楚地看出,TTS 脚本将 WAV 文件写入 May 28 21:50:11 voicekit-zero autostart.sh[620]: Traceback (most recent call last): May 28 21:50:11 voicekit-zero autostart.sh[620]: File "/home/pi/ready.py",line 27,in <module> May 28 21:50:11 voicekit-zero autostart.sh[620]: """,volume=5) May 28 21:50:11 voicekit-zero autostart.sh[620]: File "/home/pi/AIY-projects-python/src/aiy/voice/tts.py",line 52,in say May 28 21:50:11 voicekit-zero autostart.sh[620]: with tempfile.NamedTemporaryFile(suffix='.wav',dir=RUN_DIR) as f: May 28 21:50:11 voicekit-zero autostart.sh[620]: File "/usr/lib/python3.7/tempfile.py",line 686,in NamedTemporaryFile May 28 21:50:11 voicekit-zero autostart.sh[620]: (fd,name) = _mkstemp_inner(dir,prefix,suffix,flags,output_type) May 28 21:50:11 voicekit-zero autostart.sh[620]: File "/usr/lib/python3.7/tempfile.py",line 397,in _mkstemp_inner May 28 21:50:11 voicekit-zero autostart.sh[620]: fd = _os.open(file,0o600) May 28 21:50:11 voicekit-zero autostart.sh[620]: FileNotFoundError: [Errno 2] No such file or directory: '/run/user/1000/tmponnl3w02.wav' 中的临时位置,然后将其用于播放。但是,到那时,该文件已无法访问。我最好的猜测是文件系统还没有完全初始化。 (我不确定这一点,而且我对 systemd 服务没有太多经验,所以我肯定是错的。)

systemd 服务文件为 /run/user/1000/Wants 指定了 Afternetwork-online.target,当然这两者都与文件系统准备情况没有直接关系。在此之后我是否可以启动其他服务以确保文件系统已准备好进行此调用?如果没有,我可以等待几秒钟,但我更愿意构建一个应该可靠运行的更强大的系统。

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)