这是我的 Python 脚本 (main.py):
#! /usr/bin/env python
import time
# ..... some file imports from the same folder .....
try:
# .... Some setup code
while True:
if turnOffRequestHandler.turnOffIsRequested():
break;
time.sleep(1)
except BaseException as e:
pass
finally:
# ..... Some code to dispose resources
我尝试在每次启动时调用它的方式是首先编辑 rc.local 使其类似于:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
python3 /home/pi/Desktop/ProjectFolder/sample/main.py &
exit 0
然后通过导航到包含目录并执行以下命令使我的 python 脚本可执行:
chmod 755 main.py
然后,我希望在系统重新启动后让我的脚本运行。我不知道它是否运行。我能说的是它应该调用一些网络端点。我现在想知道它是否真的被执行了,但 wifi 还没有连接。
我怎么能诊断呢?因为,当我尝试像这样手动执行(在系统启动并连接 Wifi 之后)时:
pi@raspberrypi:~ $ /etc/rc.local
它正在开始,一切都按预期进行。
编辑:是否可能与我尝试执行的脚本在其中引用位于同一文件夹中的文件(不同于 /etc/..)的事实有关?。
qq_笑_17
海绵宝宝撒
相关分类