导包:
from celery import Celery
from celery.result import AsyncResult

app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)

  

项目中调用:

res = get_data.delay(fp_info) get_data为耗时的程序 id =res.id async_task = AsyncResult(id=id, app=celery) result = async_task.get() # 返回的结果

 

@celery.task
def get_data(fp):  在函数上加上修饰器
# 逻辑代码
  pass

  

 

启动redis: redis-cli
celery: celery -A app:celery worker --loglevel=info   #app为你的flask  app
启动flask: python app.py

  

 

相关文章:

  • 2021-09-16
  • 2019-08-07
  • 2022-02-23
  • 2023-03-10
  • 2021-12-17
  • 2022-02-14
  • 2021-07-16
  • 2022-03-03
猜你喜欢
  • 2022-01-21
  • 2021-11-17
  • 2022-01-13
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
  • 2021-09-22
相关资源
相似解决方案