Python 芹菜任务在尝试访问Django模型时过早存在

Python 芹菜任务在尝试访问Django模型时过早存在,python,django,celery,Python,Django,Celery,我有一个芹菜任务,需要访问django模型。我在tasks.py中的代码是 @app.task def crawlweb(listing_file_obj, marketplace): logger = logging.getLogger("gbp_web.odsa") logger.info('Started the task') listing_file_obj.status="In Progress" listing_file_obj.save() 我从v

我有一个芹菜任务,需要访问django模型。我在tasks.py中的代码是

@app.task
def crawlweb(listing_file_obj, marketplace):
    logger = logging.getLogger("gbp_web.odsa")
    logger.info('Started the task')
    listing_file_obj.status="In Progress"
    listing_file_obj.save()
我从views.py代码中调用它

def prepare_urls_to_scrap(listing_file_obj, marketplace):
    crawlweb.delay(listing_file_obj, marketplace)
    logger.info('Submitted a crawling task')
当我这样做的时候,我得到了这个错误

[2016-04-27 17:41:34,792: ERROR/MainProcess] Process 'Worker-5' pid:7362 exited with 'signal 11 (SIGSEGV)'
[2016-04-27 17:41:34,804: ERROR/MainProcess] Task odsa.tasks.crawlweb[ad90ca39-488e-4c94-ac28-88740562e934] raised unexpected: WorkerLostError('Worker exited prematurely: signal 11 (SIGSEGV).',)
Traceback (most recent call last):
   File "/Users/amer/repository/gbp_web/env/lib/python2.7/site- packages/billiard/pool.py", line 1175, in mark_as_worker_lost
human_status(exitcode)),
如果我注释掉对对象的任何访问,比如删除下面的行

    listing_file_obj.save()
这项任务做得很好。每次我尝试访问django模型时,它都会过早地存在。我试着运行代码而不把它当作一项任务,也不使用芹菜,它工作得很好

这是我的芹菜设置的样子

BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERYD_OPTS = "--concurrency=1"
这是芹菜的.py文件

from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gbp_web.settings')

app = Celery('gbp_web')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

app.conf.update(
    CELERY_TASK_RESULT_EXPIRES=3600
)
我使用的是Mac El Capitan、redis broker、django 1.9.2 scrapy 1.0.5和芹菜3.1.23


谢谢你的帮助

你实际上还没有通过芹菜打电话给我。为此,您需要执行
crawweb.delay(列出\u file\u obj,marketplace)
。您是对的,我尝试了.delay,但没有成功。我一定是在尝试确保函数在Web上爬行后进行了函数调用。我会编辑这个你还没有通过芹菜叫它。为此,您需要执行
crawweb.delay(列出\u file\u obj,marketplace)
。您是对的,我尝试了.delay,但没有成功。我一定是在尝试确保函数在Web上爬行后进行了函数调用。我会编辑这个