目录
1.实现功能
编写python脚本一直运行,判断当下是否是新的一天,如果是就执行一次任务代码
2.具体实现代码
#-*-coding:utf-8 -*-
__author__ = 'Administrator'
import os,threading,time
curTime=time.strftime("%Y-%m-%d",time.localtime())#记录当前时间
execF=False
ncount=0
def execTask():
#具体任务执行内容
print("execTask executed!")
def timerTask():
global execF
global curTime
global ncount
if execF is False:
execTask()#判断任务是否执行过,没有执行就执行
execF=True
else:#任务执行过,判断时间是否新的一天。如果是就执行任务
desTime=time.strftime("%Y-%m-%d",time.localtime())
if desTime > curTime:
execF = False#任务执行执行置值为
curTime=desTime
ncount = ncount+1
timer = threading.Timer(5,timerTask)
timer.start()
print("定时器执行%d次"%(ncount))
if __name__=="__main__":
timer = threading.Timer(5,timerTask)
timer.start()
使用Python 执行具体任务执行