芹菜:任务中的特定异常导致WorkerLostError

时间:2019-04-12 10:56:31

标签: python django task celery

我在Django celery应用程序中有一个简单的任务,例如

@shared_task
def task(some_arg):
  # Do some stuff
  if some_error:
    raise Exception("Something went wrong")

一切正常,任务按预期失败:

[...:ERROR/ForkPoolWorker-2] Task task[some-id] raised unexpected: Exception('Something went wrong',)

但是当库引发自定义异常时,我得到以下输出:

[...: WARNING/ForkPoolWorker-2] --- Logging error ---
[...: ERROR/MainProcess] Task handler raised error: WorkerLostError('Worker exited prematurely: exitcode 0.',)
Traceback (most recent call last):
  File ".../lib/python3.6/site-packages/billiard/pool.py", line 1226, in mark_as_worker_lost
    human_status(exitcode)),
billiard.exceptions.WorkerLostError: Worker exited prematurely: exitcode 0.

该如何调试?

自定义Error类如下所示:

class faultType(structType, Error):
  def __init__(self, faultcode = "", faultstring = "", detail = None):
      self.faultcode = faultcode
      self.faultstring = faultstring
      if detail != None:
          self.detail = detail

      structType.__init__(self, None, 0)

...

1 个答案:

答案 0 :(得分:0)

据我了解,您需要在另一个引发错误的库中调试问题。为此,您可以使用内置的pdb库。

import pdb
pdb.set_trace()

然后逐步执行评估。您可以通过this guide