姜戈芹菜工人__init__()错误



技术堆栈如下所示:

  • Django 前端和后端
  • 用于异步处理耗时任务的芹菜工作线程队列

在过去的一两天里,我注意到本地和生产环境中都有很多这样的堆栈跟踪:

[2012-07-05 20:31:01,583: CRITICAL/MainProcess] Task site_endpoint.tasks.async_inbound_message[a950736c-ff93-420c-9fbf-6deb2b88ff4d] INTERNAL ERROR: TypeError('__init__() takes at least 3 arguments (1 given)',)
Traceback (most recent call last):
  File "/projects/site/venv/lib/python2.7/site-packages/celery/execute/trace.py", line 192, in trace_task
    R = I.handle_error_state(task, eager=eager)
  File "/projects/site/venv/lib/python2.7/site-packages/celery/execute/trace.py", line 91, in handle_error_state
    }[self.state](task, store_errors=store_errors)
  File "/projects/site/venv/lib/python2.7/site-packages/celery/execute/trace.py", line 114, in handle_failure
    task.backend.mark_as_failure(req.id, exc, self.strtb)
  File "/projects/site/venv/lib/python2.7/site-packages/celery/backends/base.py", line 96, in mark_as_failure
    traceback=traceback)
  File "/projects/site/venv/lib/python2.7/site-packages/celery/backends/base.py", line 229, in store_result
    return self._store_result(task_id, result, status, traceback, **kwargs)
  File "/projects/site/venv/lib/python2.7/site-packages/djcelery/backends/database.py", line 26, in _store_result
    traceback=traceback)
  File "/projects/site/venv/lib/python2.7/site-packages/djcelery/managers.py", line 40, in _inner
    return fun(*args, **kwargs)
  File "/projects/site/venv/lib/python2.7/site-packages/djcelery/managers.py", line 164, in store_result
    "traceback": traceback})
  File "/projects/site/venv/lib/python2.7/site-packages/djcelery/managers.py", line 82, in update_or_create
    return self.get_query_set().update_or_create(**kwargs)
  File "/projects/site/venv/lib/python2.7/site-packages/djcelery/managers.py", line 66, in update_or_create
    obj, created = self.get_or_create(**kwargs)
  File "/projects/site/venv/lib/python2.7/site-packages/django/db/models/query.py", line 385, in get_or_create
    obj.save(force_insert=True, using=self.db)
  File "/projects/site/venv/lib/python2.7/site-packages/django/db/models/base.py", line 460, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/projects/site/venv/lib/python2.7/site-packages/django/db/models/base.py", line 543, in save_base
    for f in meta.local_fields if not isinstance(f, AutoField)]
  File "/projects/site/venv/lib/python2.7/site-packages/django/db/models/fields/subclassing.py", line 28, in inner
    return func(*args, **kwargs)
  File "/projects/site/venv/lib/python2.7/site-packages/django/db/models/fields/subclassing.py", line 28, in inner
    return func(*args, **kwargs)
  File "/projects/site/venv/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 276, in get_db_prep_save
    return self.get_db_prep_value(value, connection=connection, prepared=False)
  File "/projects/site/venv/lib/python2.7/site-packages/django/db/models/fields/subclassing.py", line 53, in inner
    return func(*args, **kwargs)
  File "/projects/site/venv/lib/python2.7/site-packages/picklefield/fields.py", line 154, in get_db_prep_value
    value = force_unicode(dbsafe_encode(value, self.compress, self.protocol))
  File "/projects/site/venv/lib/python2.7/site-packages/picklefield/fields.py", line 57, in dbsafe_encode
    value = b64encode(dumps(deepcopy(value), pickle_protocol))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 328, in _reconstruct
    args = deepcopy(args, memo)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 237, in _deepcopy_tuple
    y.append(deepcopy(a, memo))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 329, in _reconstruct
    y = callable(*args)
TypeError: __init__() takes at least 3 arguments (1 given)

发生这种情况时查看数据库调用,我可以看到正在执行以下查询:

LOG:  statement: SELECT "celery_taskmeta"."id", "celery_taskmeta"."task_id", "celery_taskmeta"."status", "celery_taskmeta"."result", "celery_taskmeta"."date_done", "celery_taskmeta"."traceback" FROM "celery_taskmeta" WHERE "celery_taskmeta"."task_id" = 'a950736c-ff93-420c-9fbf-6deb2b88ff4d' 
LOG:  statement: SAVEPOINT s140735259576672_x4
LOG:  statement: ROLLBACK
LOG:  statement: BEGIN
LOG:  statement: SELECT "celery_taskmeta"."id", "celery_taskmeta"."task_id", "celery_taskmeta"."status", "celery_taskmeta"."result", "celery_taskmeta"."date_done", "celery_taskmeta"."traceback" FROM "celery_taskmeta" WHERE "celery_taskmeta"."task_id" = 'a950736c-ff93-420c-9fbf-6deb2b88ff4d' 
LOG:  statement: SAVEPOINT s140735259576672_x5
LOG:  statement: ROLLBACK
LOG:  statement: BEGIN
LOG:  statement: SELECT "celery_taskmeta"."id", "celery_taskmeta"."task_id", "celery_taskmeta"."status", "celery_taskmeta"."result", "celery_taskmeta"."date_done", "celery_taskmeta"."traceback" FROM "celery_taskmeta" WHERE "celery_taskmeta"."task_id" = 'a950736c-ff93-420c-9fbf-6deb2b88ff4d' 
LOG:  statement: SAVEPOINT s140735259576672_x6

我很难理解这个无效对象初始化的来源是什么。 有人有想法吗?

看起来您正在使用新的遗物远程性能监控/取证分析。 我以前在使用旧版本的库时见过这种问题。 我建议您检查以确保您使用的是最新版本的客户端库。

这发生在我身上,我通过阅读 Python 多处理池在连接挂起来解决它? 和 http://bugs.python.org/issue9400。

问题:

Celery 以某种方式腌制它获得的异常并将它们发送到某个地方(我猜是数据库/代理)。因此,如果在任何时候,Celery 任务引发不可腌制的异常,就会发生此错误。

解决方案:

您必须确保处理 Celery 任务代码可能引发的所有奇怪异常。Traceback可以给你提示,但它可能不是很准确。

如果您真的不知道异常来自哪里,请尝试将任务代码放在try...except: pass块中。

相关内容

  • 没有找到相关文章

最新更新