python 定时器使用

#!/usr/bin/python
# -*- coding:utf-8 -*-

import datetime,os,platform,time


def run_Task():
import SendMail
SendMail.SendMail()
#os_platform=platform.platform()
##if os_platform.startswith("Darwin"):
#print "this is mac os system!"
#os.system("ls")
#elif os_platform.startswith("Linux"):
#print "this is Linux system!"
#os.system("ls")

def timerFun(sched_Timer):
flag = 0
#now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
while True:
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
#print now,sched_Timer
if now == str(sched_Timer):
print "*"*30
run_Task()
flag = 1
time.sleep(60)
#break
else:
if flag==1:
sched_Timer=sched_Timer+datetime.timedelta(days=1)
flag=0

if __name__ =="__main__":
sched_Timer = datetime.datetime(2018,5,8,9,0,0)
print "run the timer task at{0}".format(sched_Timer)
timerFun(sched_Timer)

猜你喜欢

转载自www.cnblogs.com/ddpeng/p/9008102.html