芹菜与烧瓶和UWSGI

时间:2020-01-22 09:34:52

标签: python-3.x flask celery uwsgi

我有一个带有简单芹菜任务的简单应用烧瓶:

boolean isMapStyleOne=false;

@Override
public void onClick(View v) {
    switch (v.getId())
    {
        case R.id.change_map:{
            if(isMapStyleOne) {
                googleMap.setMapStyle(
                        MapStyleOptions.loadRawResourceStyle(
                                requireContext(), R.raw.map_styles_1));
                isMapStyleOne=false;
            } else{
                googleMap.setMapStyle(
                        MapStyleOptions.loadRawResourceStyle(
                                requireContext(), R.raw.map_styles_2));
                isMapStyleOne=true;
            }
        }
    }

}

当我尝试将您的示例与uwsgi一起使用时,却遇到与您几乎相同的错误。 首先,我仅使用python运行它:

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)

和代理使用以下命令:

python app.py

一切正常。现在,我尝试使用uwsgi启动flask应用程序。

celery -A app.celery worker -l info

但是,当我沿途行驶时,遇到以下错误:

[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

2 个答案:

答案 0 :(得分:0)

尝试明确指定任务名称,例如:

@celery.task(name='app.celery.add')
def add(x, y):
    return x + y

为确保更改生效,请在进行更改后重新启动celery worker并使用*.pyc清理所有find . -name '*.pyc' -delete文件

答案 1 :(得分:0)

请看看这个:https://uwsgi-docs.readthedocs.io/en/latest/AttachingDaemons.html

虽然以下配置与您的环境不完全匹配,但我希望这可以帮助。

[uwsgi]
base = /home/project
chdir = %(base)
module = app
pythonpath = %(base)
virtualenv = %(base)/venv
wsgi-file = %(base)/app.py
master = true
smart-attach-daemon = %(base)/tmp/celery.pid %(virtualenv)/bin/celery -A %(module).celery  worker --pidfile=%(base)/tmp/celery.pid
socket = %(base)/socket.sock
chmod-socket = 777
processes = 4
threads = 4
logto = %(base)/log/%n.log
stats = 127.0.0.1:9191