芹菜和弦因valueerror的失败:没有足够的价值打开包装(预期2,得到1)

发布于 2025-01-19 16:11:21 字数 920 浏览 4 评论 0原文

我正在运行 ubuntu 的 docker 容器中运行 celery v5.2.3。

在这里,我试图让芹菜和弦发挥作用,但我所做的每一次尝试都会给我带来:

    File "/usr/local/lib/python3.7/site-packages/celery/result.py", line 1056, in result_from_tuple
    res, nodes = r
ValueError: not enough values to unpack (expected 2, got 1)

出现此错误后,和弦会不断重试:

retry: Retry in 1.0s: ValueError('not enough values to unpack (expected 2, got 1)')

我尝试运行的任务如下:

@celery_app.task(shared=False)
def add(x, y):
    return x + y


@celery_app.task(shared=False)
def tsum(numbers):
    return numbers

@celery_app.task(name="celery.test")
def test():
    x = chord([add.s(i, i) for i in range(10)], body=tsum.s())
    r = x.apply_async()
    r.get()

我的示例运行了 9/10 次迭代,但随后失败。

芹菜工人正在运行:

celery -A scheduler worker -P eventlet -l info 

你们谁能告诉我我做错了什么,因为我在互联网上找不到任何解释这个问题的东西?

I am running celery v5.2.3 in a docker container running ubuntu.

Here I am trying to get celery chords to work but every attempt I make give me:

    File "/usr/local/lib/python3.7/site-packages/celery/result.py", line 1056, in result_from_tuple
    res, nodes = r
ValueError: not enough values to unpack (expected 2, got 1)

After this error the chord keeps retrying with:

retry: Retry in 1.0s: ValueError('not enough values to unpack (expected 2, got 1)')

The tasks I am trying to run is as follows:

@celery_app.task(shared=False)
def add(x, y):
    return x + y


@celery_app.task(shared=False)
def tsum(numbers):
    return numbers

@celery_app.task(name="celery.test")
def test():
    x = chord([add.s(i, i) for i in range(10)], body=tsum.s())
    r = x.apply_async()
    r.get()

My sample runs for 9/10 iterations, but then fails.

The celery worker is running with:

celery -A scheduler worker -P eventlet -l info 

Can any of you tell me what I am doing wrong as I cannot find anything on the internet explaining this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷炫老祖宗 2025-01-26 16:11:21

对于未来任何不幸的人来说,都会遇到这个问题。

这个问题是因为我们为 celery 定制了 mongo 后端。
在这里,我们为任务定义了元字段,如下所示:

meta = {
            "_id": task_id,
            "status": status,
            "result": result,
            "date_done": datetime.utcnow(),
            "traceback": traceback,
            "children": self.encode(
                self.current_task_children(request),
            ),
            "task_name": task_name,
            "task_args": task_args,
            "task_kwargs": task_kwargs,
            "worker": worker,
        }

但是,由于 celery 期望孩子字段是孩子列表或无,我的问题是因为孩子字段总是由空列表填充。

通过将孩子改为:

"children": self.encode(
    self.current_task_children(request),
)
if len(self.current_task_children(request)) > 0
else None,

问题就可以解决。

如果有人经历过这个,我希望这会有所帮助

For any unlucky soul in the future that should experience this issue.

The issue was cause with us having a custom implementation of the mongo backend for celery.
Here we defined the meta fields for the tasks as follows:

meta = {
            "_id": task_id,
            "status": status,
            "result": result,
            "date_done": datetime.utcnow(),
            "traceback": traceback,
            "children": self.encode(
                self.current_task_children(request),
            ),
            "task_name": task_name,
            "task_args": task_args,
            "task_kwargs": task_kwargs,
            "worker": worker,
        }

However as celery expects the children field to be a list of children or None, my issue was because the children field would always be populated by an empty list.

By changing children to:

"children": self.encode(
    self.current_task_children(request),
)
if len(self.current_task_children(request)) > 0
else None,

The issue would be solved.

I hope this will help if anyone should experience this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文