首页 > 解决方案 > 在烧瓶中使用 celery 出现退出代码 2 错误

问题描述

关于烧瓶和芹菜的问题 -

init.py

from celery import Celery
from flask import Flask
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost'
app.config['CELERY_BROKER_URL'] = 'redis://localhost'

celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
training.py

from project import celery

training = Blueprint('training', __name__)

@training.route('/projectdetails/training', methods=["GET", "POST"])
@login_required
def start_training():

    train_test.delay()

    return render_template('test.html')

@celery.task()
def train_test():
  # a ML training task. 

我有我的 redis 服务器和我的 celery worker celery -A myproject.celery worker --loglevel=info

这是我不断收到的错误 -

[2021-04-01 17:25:11,604: ERROR/MainProcess] Process 'ForkPoolWorker-8' pid:67580 exited with 'exitcode 2'
[2021-04-01 17:25:11,619: ERROR/MainProcess] Task handler raised error: WorkerLostError('Worker exited prematurely: exitcode 2.')
Traceback (most recent call last):
  File "/Users/rohankamath/Desktop/lol/env/lib/python3.7/site-packages/billiard/pool.py", line 1267, in mark_as_worker_lost
    human_status(exitcode)),
billiard.exceptions.WorkerLostError: Worker exited prematurely: exitcode 2.

尝试在exitcode2上搜索含义,找不到任何东西。

标签: pythoncelery

解决方案


当我的代码中出现一些导入错误时,这发生在我身上。您可以尝试不使用 celery 运行(直接调用 main 函数),看看它是否有效?


推荐阅读