文档:
安装
pip install Flask-APScheduler
示例
from flask import Flask
from flask_apscheduler import APScheduler
class Config(object):
JOBS = [
{
'id': 'job1',
'func': '__main__:job1', # 注意函数和包名中间使用':'
'args': (1, 2),
'trigger': 'interval',
'seconds': 10
}
]
def job1(a, b):
print(str(a) + ' ' + str(b))
if __name__ == '__main__':
app = Flask(__name__)
app.config.from_object(Config())
scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()
app.run()