Flask-apscheduler获取或修改上下文中config数据
__init__.py
1 from flask_apscheduler import APScheduler 2 ... 3 4 scheduler = APScheduler() 5 6 from app import app 7 8 def create_app(config_name): 9 app = Flask(__name__) 10 11 CORS(app, resources=r'/*') 12 13 # 根据配置模式的名字获取配置参数的类 14 config_class = config_map.get(config_name) 15 app.config.from_object(config_class) 16 17 # 启动定时器 18 scheduler.init_app(app) 19 scheduler.start() 20 ... 21 22 return app
test.py
1 from . import scheduler 2 3 @scheduler.task('interval', id='aa', seconds=300, next_run_time=datetime.datetime.now()) 4 def aa(): 5 with scheduler.app.app_context(): 6 print(scheduler.app.config["config_data"]) 7 scheduler.app.config["config_data"] = ...