使用Tornado执行定时任务

import datetime

from tornado import web,ioloop


class MainHandler(web.RequestHandler):
    def get(self):
        self.write("Hello Tornado")


def callbak1():
    print("每隔2s执行")


def callbak2():
    print("每隔5s执行")



if __name__ == '__main__':
    application = web.Application([
        (r"/",MainHandler),
        ])

    application.listen(8001)
    ioloop.PeriodicCallback(callbak1,2000).start()
    ioloop.PeriodicCallback(callbak2,5000).start()
    ioloop.IOLoop.instance().start()

~~~

posted on 2020-03-10 12:06  江湖乄夜雨  阅读(1542)  评论(0编辑  收藏  举报