重启树莓派的 Python 脚本 [英] Python script to restart a Raspberry Pi

查看:55
本文介绍了重启树莓派的 Python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我想要的很简单.

Python 脚本在 23 小时 59 分钟后重新启动我的 Raspberry Pi.我尝试这样做的原因,而不是使用 cron 作业设置时间,是 Pi 没有用于时钟的板载电池,所以我不在乎时间是什么(如果连接到互联网,它将获取当前时间),从脚本开始倒计时 23 小时 59 分钟.

Python script to restart my Raspberry Pi after 23 hours and 59 minutes. The reason I am trying to do this, instead of set times with a cron job, is the Pi has no onboard battery for a clock so I don't care what the time is (if connected to internet, it will source current time), just a count down of 23 hours and 59 minutes from the script starting.

这是我所知道的;

def restart():
SendEmail = SendEmail "SYSTEM RESTART", "ncam.py auto restart initiated"      msg['Subject'], body)
command = "/usr/bin/sudo /sbin/shutdown -r now"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]

我还想给自己发一封电子邮件,上面设置的参数如上.

Also I want to send an email to myself with the set parameters as above.

推荐答案

你会想要一些这样的变体:

You are going to want some variant of this:

 import time
 import os
 currentTime = time.time()
 tomorrow = currentTime + 86340000
 while time.time() < tomorrow:
     do.yourCode()
    
 os.system("poweroff")

在你的函数中加入类似的东西,它会做你想做的.

Put something like that in your function and it will do what you want.

这篇关于重启树莓派的 Python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆