定时任务

示例

from lessweb import Application
import time
import threading

COUNT = 0
def routine():
    global COUNT
    while...:
        time.sleep(1)
        COUNT += 1


def get_count():
    return {'count': COUNT}


app = Application()
app.add_get_mapping('/', get_count)

threading.Thread(target=routine).start()
app.run()

打开浏览器访问http://localhost:8080/,每隔几秒刷新一下页面,会发现count的值在不断增加。