使用tornado实现轮询:
from tornado import web, ioloop import datetime class MainHandler(web.RequestHandler): def get(self): self.write('Hello Tornado') def f2s(): print '2s ', datetime.datetime.now() def f5s(): print '5s ', datetime.datetime.now() if __name__ == '__main__': application = web.Application([ (r'/', MainHandler), ]) application.listen(8081) ioloop.PeriodicCallback(f2s, 2000).start() # start scheduler 每隔2s执行一次f2s ioloop.PeriodicCallback(f5s, 5000).start() # start scheduler ioloop.IOLoop.instance().start()
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/7425.html