首页 > 解决方案 > 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 上运行

标签: pythonapplication-restart

解决方案


我建议你让脚本简单地从网页中获取信息,然后对你的字典做任何需要做的事情并结束。只有一次。然后,您可以使用 Windows 任务计划程序或使用 linux 上的 Cron 作业安排此脚本在每天凌晨 4:00 运行。是有关如何设置 cron 作业以运行 python 脚本的链接。


推荐阅读