python - Windows或Linux上的Python重启文件
问题描述
我目前有一个很大的长文件,可以查询网页以构建字典。我希望这个文件每天凌晨 4 点重新启动,因为网页会更新最新信息。我需要在while True:
循环中放入什么?
当前状态:
##Various Imports
##Selenium code to get details
##Dictionary Compile
while True:
now = datetime.datetime.now()
current_time = now.strftime("%H:%M:%S")
if current_time == ("04:00:00"):
##The Code to Restart the process goes here
else:
#Other Stuff happens with the dictionary
在 Windows 上构建和测试,但最终将在 Raspberry Pi 上运行
解决方案
我建议你让脚本简单地从网页中获取信息,然后对你的字典做任何需要做的事情并结束。只有一次。然后,您可以使用 Windows 任务计划程序或使用 linux 上的 Cron 作业安排此脚本在每天凌晨 4:00 运行。这是有关如何设置 cron 作业以运行 python 脚本的链接。
推荐阅读
- go - 为什么我从应用程序收到 dns 错误,而不是从我的浏览器
- python - 如何在 tkinter GUI 中创建交互式动画
- email - 防止将邮件发送到 gmail 中的“促销”
- python - 需要了解 SubwordTextEncoder 分词器背后的概念
- google-cloud-platform - GCP 云构建查看原始日志链接
- r - 如何获取在指定环境中评估调用对象时使用的所有参数的值
- python - 创建将整个图像数据集转换为注释文件(.xml 文件)的自动方法
- css - 使用 nextjs 时 Css 未在生产模式下加载
- vuejs3 - 为什么 Vue3 组合 API 比单纯的辅助类更好?
- node.js - TypeError:res.status 不是错误处理中间件中的函数