微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

chronospy 定时任务模块

程序名称:chronospy

授权协议: GPLv2

操作系统: 跨平台

开发语言: Python

chronospy 介绍

Chronos 是通过 Tornado IOLoop 驱动的多线程/多进程任务定时工具。

import logging
import time
import tornado
import chronos
import os
import urllib2

def test_process():
    LOGGER.info("process pid %s", os.getpid())


def test(word):
    LOGGER.info("an other task, say '%s'", word)


def say():
    response = urllib2.urlopen('https://www.google.com/')
    html = response.read()
    LOGGER.info(html[:10])


def init():
    global LOGGER
    debug = True
    level = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(level=level,
                        format='%(asctime)s %(levelname)-8s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%s', filemode='a+')

    LOGGER = logging.getLogger("demo")

    # bind a ioloop or use default ioloop
    chronos.setup()  # chronos.setup(tornado.ioloop.IOLoop())
    chronos.schedule('say', chronos.every_second(1), say)
    chronos.schedule('say2', chronos.every_second(1), test_process, once=True, process=True)
    chronos.schedule('say3', chronos.every_second(1), lambda: test("test3"))
    chronos.start(True)

if __name__ == '__main__':

    init()

chronospy 官网

https://github.com/whiteclover/chronos

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐