我正在开发一个Django应用本地,需要将CSV文件作为输入并对该文件运行一些分析。我在本地运行Celery,RabbitMQ和Web服务器。当我导入文件时,我在Celery服务器上看到以下错误:
[2015-12-11 16:58:53,906: WARNING/MainProcess] celery@Joes-MBP ready.
[2015-12-11 16:59:11,068: ERROR/MainProcess] Task program_manager.tasks.analyze_list_import_program[db22de16-b92f-4220-b2bd-5accf484c99a] raised unexpected: WorkerLostError('Worker exited prematurely: signal 11 (SIGSEGV).',)
Traceback (most recent call last):
File "/Users/joefusaro/rl_proto2/venv/lib/python2.7/site-packages/billiard/pool.py", line 1175, in mark_as_worker_lost
human_status(exitcode)),
WorkerLostError: Worker exited prematurely: signal 11 (SIGSEGV).
我不确定如何进一步解决这个问题;如果它有助于我从program_manager / tasks.py复制相关代码:
from __future__ import absolute_import
import csv
import rollbar
from celery import shared_task
from celery.utils.log import get_task_logger
from qscore.models import QualityScore
from integrations.salesforce.prepare import read_csv
from qscore.quality_score import QualityScoreCalculator
logger = get_task_logger(__name__)
@shared_task
def analyze_list_import_program(program):
program.status = 'RUN'
program.save()
df = read_csv(program.csv_file.file)
try:
qs = program.get_current_quality_score()
qs_calc = QualityScoreCalculator(df, qs)
qscore_data = qs_calc.calculate()
QualityScore.objects.filter(id=qs.id).update(**qscore_data)
except Exception as e:
rollbar.report_exc_info()
program.status = 'ERROR'
else:
program.status = 'COMPL'
finally:
program.save()
答案 0 :(得分:0)
问题是您的Celery任务正在尝试释放/反序列化实际的Django对象program
。将program_id
作为参数传递给任务,并在任务本身中重新获取对象。
答案 1 :(得分:0)
这可以通过在单个任务函数中导入python包来解决,而不是在tasks.py的顶部。
除了从 .celery from <project>.celery import app
导入应用程序外,我已经删除了在 tasks.py 文件顶部导入的所有包,然后在各个任务函数中导入包。它奏效了!