30 lines
716 B
Python
30 lines
716 B
Python
# -*- coding: utf-8 -*-
|
|
# -*- coding:utf-8 -*-
|
|
from tornado import web, ioloop
|
|
import datetime
|
|
import time
|
|
|
|
class MainHandler(web.RequestHandler):
|
|
def get(self):
|
|
self.write('Hello Kingsome, I am alive!')
|
|
|
|
|
|
def add_task():
|
|
# print '2s ', datetime.datetime.now()
|
|
time.sleep(2)
|
|
print(
|
|
"执行f2s")
|
|
|
|
|
|
def remove_task():
|
|
# print '5s ', datetime.datetime.now()
|
|
print(
|
|
"执行f5s")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
application = web.Application([(r'/', MainHandler), ])
|
|
application.listen(8081)
|
|
ioloop.PeriodicCallback(add_task, 2000).start() # start scheduler 每隔2s执行一次f2s
|
|
ioloop.PeriodicCallback(remove_task, 5000).start() # start scheduler 每隔5s执行一次f5s
|
|
ioloop.IOLoop.instance().start() |