解决 fastapi 中 APScheduler 与 uvicorn 冲突问题(qbit)
文章目录
问题描述
环境
Ubuntu 20.04 Python 3.8.5 APScheduler 3.8.x/3.9.x uvicorn 0.15.0 - 0.17.6- 在上述环境下,
APScheduler的定时任务不能运行 uvicorn 0.14.0与APScheduler搭配无此问题- 在
Windows下uvicorn与APScheduler任意版本搭配也无此问题
解决办法
在
app的startup事件中启动定时器即可@app.on_event("startup") async def start_scheduler(): AsyncSched = AsyncIOScheduler(timezone="Asia/Shanghai") scheduler.add_job(...) scheduler.start()- 参考 uvicorn can't reload when i use apscheduler and fastapi together
2023年3月,fastapi 0.93.0 提出用asynccontextmanager lifespan替代startup shutdown
本文出自 qbit snap
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论