尝试在fastapi 中使用 apscheduler 报错:
LookupError: No trigger by the name "interval" was found
解决办法:使用实例化的trigger
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers import interval
scheduler = BackgroundScheduler()
trigger = interval.IntervalTrigger(seconds=3)
scheduler.add_job(lambda: job_func(ws), trigger=trigger, id='status_update_job', replace_existing=True)
另一个错误:
在我将定时任务逻辑封装到类中时,
报错:Can't pickle coroutine objects when ProcessPoolExecutor is used in class
原因是定时任务序列化保存时出错,必须使用静态方法:原文:python - Can't pickle coroutine objects when ProcessPoolExecutor is used in class - Stack Overflow