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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM