【发布时间】:2020-01-22 09:34:52
【问题描述】:
我有一个简单的应用程序烧瓶和一个简单的 celery 任务:
from flask import Flask
from celery import Celery
app = Flask(__name__)
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
@celery.task
def add(x, y):
return x + y
@app.route('/', methods=['GET'])
def test_func():
res = add.delay(4,5)
while not res.ready():
pass
data = res.get()
return str(data)
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=True)
当我尝试将您的示例与 uwsgi 一起使用时,但遇到的错误几乎与您相同。 首先,我简单地用 python 运行它:
python app.py
以及使用以下命令的代理:
celery -A app.celery worker -l info
一切正常。现在我尝试使用 uwsgi 启动烧瓶应用程序。
[uwsgi]
mount = /=/home/admin/flask-celery/app.py
callable = app
virtualenv = /home/admin/flask-celery/.venv
socket = :3031
master = true
processes = 2
threads = 4
http = :9000
但是当我继续我的路线时,我遇到了以下错误:
celery.exceptions.NotRegistered: 'uwsgi_file__home_admin_flask-celery_app.add'
【问题讨论】:
标签: python-3.x flask celery uwsgi