zoukankan      html  css  js  c++  java
  • django 定时脚本

    python 第三方定时执行
    from datetime import datetime
    import time
    import os
    
    from apscheduler.schedulers.background import BackgroundScheduler
    
    
    def tick():
        print('Tick! The time is: %s' % datetime.now())
    
    
    scheduler = BackgroundScheduler()
    scheduler.add_job(tick, 'interval', minutes=1)
    scheduler.start()    #这里的调度任务是独立的一个线程
    
    if __name__ == '__main__':
        scheduler = BackgroundScheduler()
        scheduler.add_job(tick, 'interval', seconds=3)
        # scheduler.add_job(tick, 'date', run_date='2016-02-14 15:01:05')#在指定的时间,只执行一次
        scheduler.start()    #这里的调度任务是独立的一个线程
        print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
    
        try:
            # This is here to simulate application activity (which keeps the main thread alive).
            while True:
                time.sleep(2)    #其他任务是独立的线程执行
                print('sleep!')
        except (KeyboardInterrupt, SystemExit):
            # Not strictly necessary if daemonic mode is enabled but should be done if possible
            scheduler.shutdown()
            print('Exit The Job!')
    

      

  • 相关阅读:
    seaborn可视化NOTE
    快速入门pandas
    protege下载安装使用
    用上Latex实现编辑伪代码
    决策树可视化
    关于时间
    地理三维模型制作
    Python使用记录
    编码格式
    素数生成算法小结
  • 原文地址:https://www.cnblogs.com/flash55/p/9032960.html
Copyright © 2011-2022 走看看