flask celery 的神坑

一、flask运行在debug模式的时候,celery无法收到flask中发送给celery的异步任务

run.py

if __name__ == '__main__':
    # app.run(host="0.0.0.0", port=8000, debug=True)          # 以debug模式运行flask
    # 使用debug模式时,celery异步任务不能执行,但定时任务可以执行
    app.run(host="0.0.0.0", port=8000)

task.py

from celery import shared_task
@shared_task():
def add(a, b)
    c = a + b
    return c

# 调用celery的异步任务add函数
add.delay(a=1, b=2)

执行add.delay(a=1, b=2)的时候,在flask的debug模式下就无法执行

猜你喜欢

转载自www.cnblogs.com/lanlingshao/p/10044754.html