![](/img/trans.png)
[英]restart apache every 12 hours using linux service and python file
[英]Python restart file on windows or linux
我目前有一個很大的長文件,可以查詢網頁以構建字典。 我希望這個文件每天凌晨 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 上運行
我建議你讓腳本簡單地從 web 頁面獲取信息,然后對你的字典做任何需要做的事情並結束。 只有一次。 然后,您可以使用 Windows 任務計划程序或 linux 上的 Cron 作業安排此腳本在每天凌晨 4:00 運行。 這是有關如何設置 cron 作業以運行 python 腳本的鏈接。
如果您想要 Python 中的cron
作業的功能,您可以使用調度庫。 看起來它支持保持腳本運行,然后在凌晨 4 點重新啟動。 可以在這個 StackOverflow 問題上閱讀更多內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.