PYTHON 定时任务

# coding=utf-8
from apscheduler.schedulers.blocking 
import BlockingSchedulerfrom datetime 
import datetime
import timeimport os
import redis

def tick():    
       print "-----------------------"    
       print 'Start: %s' % datetime.now()    
       print 'End: %s' % datetime.now()    
       print "-----------------------"    
       print '\n'# 每隔三秒执行一次

if __name__ == '__main__':    
    scheduler = BlockingScheduler()    
    scheduler.add_job(tick, 'cron', month='1-12', hour='0')    #1到12个月,每天 00.00开始执行任务
    print 'Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')    
    try:        
        scheduler.start()    
    except KeyboardInterrupt, SystemExit:        
        scheduler.shutdown()

你可能感兴趣的:(PYTHON 定时任务)