美文网首页
简单python定时器(Python定时任务框架APSchedu

简单python定时器(Python定时任务框架APSchedu

作者: 心愿2016 | 来源:发表于2017-07-11 17:19 被阅读857次

    import threading
    def fun_timer():
    print('hello Timer!')
    global timer
    timer = threading.Timer(5.5, fun_timer)
    timer.start()

    timer = threading.Timer(1, fun_timer)
    timer.start()

    timer.sleep(15) #15秒后停止定时器
    timer.cancel() ##取消
    Python定时任务框架APScheduler
    http://www.cnblogs.com/hushaojun/p/5189109.html
    ===========================================================

    from scrapy.crawler import Crawler, CrawlerProcess
    from scrapy.utils.project import get_project_settings

    项目启动器

    STARTER = CrawlerProcess(get_project_settings())
    from apscheduler.schedulers.background import BlockingScheduler
    def hellow():
    print('11111111111')

    def sory():
    print('2222222222222')

    process = CrawlerProcess(get_project_settings())
    sched = BlockingScheduler()

    sched.add_job(hellow, 'cron', day_of_week='0-4', hour='9', minute='25')

    configs = [{'day_of_week': '0-4', 'hour': 9, 'minute': '30-59', 'second': '/30'},
    {'day_of_week': '0-4', 'hour': 10, 'second': '
    /30'},
    {'day_of_week': '0-4', 'hour': 11, 'minute': '0-35', 'second': '/30'},
    {'day_of_week': '0-4', 'hour': '13-14', 'second': '
    /30'},
    {'day_of_week': '0-4', 'hour': 15, 'minute': '0-5', 'second': '*/30'}, ]

    for config in configs:
    sched.add_job(sory, 'cron', **config)
    sched.start()
    process.start()

    相关文章

      网友评论

          本文标题:简单python定时器(Python定时任务框架APSchedu

          本文链接:https://www.haomeiwen.com/subject/scpmhxtx.html