gpt4 book ai didi

python - 如何在树莓派完全启动后自动运行 Python 脚本?

转载 作者:太空宇宙 更新时间:2023-11-04 09:33:21 28 4
gpt4 key购买 nike

我的脚本是/home/hello.py,它使用的是 Bottle 网络框架。我的脚本需要在 Raspberry Pi 连接到我的本地网络后 运行。如果我尝试在启动时自动运行它,它不会工作,因为网络连接还没有准备好。

我知道我可以使用“crontab -e”并添加@reboot sleep 60 秒——但我认为 sleep 不太可靠。

我见过的所有其他“启动时运行脚本”问题都没有帮助,因为它们在启动过程中过早运行脚本。

有没有办法检查树莓派是否已连接,然后让我的 python 脚本自动运行?

最佳答案

您可以在“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”是你的代码位置

关于python - 如何在树莓派完全启动后自动运行 Python 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29204423/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com