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

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()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容