用来计算2个时间的时间差。
调用的时间建议采用挂载的方式,即:
nohup python -u xxx.py > nohup.test.log 2>&1 &
import time
import os
a = 1650380930.2743425 # 上一刻时间
'''
1. time.time()生成
2. time.mktime(time.strptime("2022-04-20 07:33:00","%Y-%m-%d %H:%M:%S")) 特定时间生成
'''
last_hours= -1
last_minutes= -1
last_seconds = -1
while True:
b = time.time() ## 当前时间
dist = b-a
minutes, seconds = divmod(dist, 60)
hours, minutes = divmod(minutes, 60)
### days, hours = divmod(hours, 24)
if minutes != last_minutes: ## 为了打印看看程序是否在走
print ('hours = ', hours, ' , minutes = ', minutes )
last_minutes = minutes
if hours > 3: ## 时间间隔达到了,运行shell 文件
data = os.popen('./test.sh')
print (data.read())
break