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!')
    

      

  • 相关阅读:
    python爬虫
    绕过CDN查找网站真实IP方法收集
    拖库
    伪静态注入的总结
    国外安全网站信息收集
    python字典去重脚本
    AOP 的利器:ASM 3.0 介绍
    JDK工具
    JVM性能调优监控工具
    DMZ
  • 原文地址:https://www.cnblogs.com/flash55/p/9032960.html
Copyright © 2011-2022 走看看