我的脚本是/home/hello.py,它正在使用Bottle Web框架。我的脚本需要在 Raspberry Pi连接到我的本地网络后运行。如果我尝试在启动时自动运行它,它就不起作用,因为网络连接还没有准备就绪。
我知道我可以使用" crontab -e"并添加@reboot睡60秒 - 但我不认为睡眠过于可靠。
所有其他"在启动时运行脚本"我已经看到的问题没有帮助,因为他们在启动过程中过早地运行脚本。
无论如何检查树莓派是否已连接,然后自动运行我的python脚本?
答案 0 :(得分:2)
您可以在“all_interfaces_up”之后的“/etc/network/if-up.d/upstart”中添加代码,如下所示:
all_interfaces_up() {
python /your/code/path/codename.py
# return true if all interfaces listed in /etc/network/interfaces as 'auto'
# are up. if no interfaces are found there, then "all [given] were up"
“/your/code/path/codename.py”是您的代码位置
答案 1 :(得分:0)
尚未声名对以前的解决方案发表评论,而是建议
all_interfaces_up() {
/your/code/path/codename.py
# return true if all interfaces listed in /etc/network/interfaces as 'auto'
# are up. if no interfaces are found there, then "all [given] were up"
试试这个:
all_interfaces_up() {
python /your/code/path/codename.py
# return true if all interfaces listed in /etc/network/interfaces as 'auto'
# are up. if no interfaces are found there, then "all [given] were up"
当您尝试运行python脚本时,需要使用python
执行。