下载Flask
pip install flask
上代码
from flask import Flask from apscheduler.schedulers.background import BackgroundScheduler import pytz app = Flask(__name__) @app.route(‘/‘) def hello_world(): return ‘Hello World ! = ‘ + str(a) global a a = 2 def job1(): global a a = a + 1 print("做了加1处理") def init(): timez = pytz.timezone(‘Asia/Shanghai‘) sched = BackgroundScheduler(timezone=timez) sched.add_job(job1, ‘interval‘, seconds=5, args=[], max_instances=1) sched.start() if __name__ == ‘__main__‘: init() app.run()
注意:用pycharm创建的Flask项目默认是不执行“__main__”的,配置方法如下图:
转载请注明博客出处:http://www.cnblogs.com/cjh-notes/
原文:https://www.cnblogs.com/cjh-notes/p/12197771.html