【问题标题】:Celery raises ValueError: not enough values to unpackCelery 引发 ValueError:没有足够的值来解包
【发布时间】:2018-01-26 10:51:07
【问题描述】:

尝试使用 Celery 运行简单示例并收到异常。 RabbitMQ 在 Docker 中启动,也尝试在本地启动它。 Celery 在本地 Windows 主机上工作

from celery import Celery

app = Celery('tasks', broker='amqp://192.168.99.100:32774')

@app.task()
def hello():
    print('hello')


if __name__ == '__main__':
    hello.delay()

我的错误文本摘录:

[2017-08-18 00:01:08,632: ERROR/MainProcess] Task handler raised error: ValueError('not enough values to unpack (expected 3, got 0)',)
Traceback (most recent call last):                                              
    File "c:\users\user\celenv\lib\site-packages\billiard\pool.py", line 358, in workloop                        
        result = (True, prepare_result(fun(*args, **kwargs)))                                  
    File "c:\users\user\celenv\lib\site-packages\celery\app\trace.py", line 525, in _fast_trace_task
        tasks, accept, hostname = _loc
ValueError: not enough values to unpack (expected 3, got 0)

【问题讨论】:

  • 哪个 celery 版本?据我所知,自 celery 4 以来,windows 不支持 celery
  • @ItayB 谢谢!我在 Windows 上的 celery 中发现了这个问题,但我不知道版本 4。我使用的是 4.1.0。
  • 添加为答案,您可以投票/接受

标签: python celery


【解决方案1】:

它对我有用:

celery -A my_project_name worker --pool=solo -l info

基本上事情变成单线程并被支持

【讨论】:

    【解决方案2】:

    哪个芹菜版本?据我所知,自 celery 4 起,windows 不支持 celery

    【讨论】:

      【解决方案3】:

      Celery 4.0+ 尚未正式支持 Windows。但它仍然可以在 Windows 上用于某些开发/测试目的。

      如下使用eventlet

      pip install eventlet
      celery -A <module> worker -l info -P eventlet
      

      它适用于Windows 10 + celery 4.1 + python 3

      ===== 2018-11 更新 =====

      Eventlet 在 subprocess.CalledProcessError 上有问题:

      https://github.com/celery/celery/issues/4063

      https://github.com/eventlet/eventlet/issues/357

      https://github.com/eventlet/eventlet/issues/413

      所以试试gevent吧。

      pip install gevent
      celery -A <module> worker -l info -P gevent
      

      这对我有用 Windows 10 + celery 4.2 + python 3.6

      【讨论】:

      • 应该选择这个答案
      • gevent 为我工作。 eventlet 给我带来了 eventlet 版本 0.24.1 和 Celery 4.3.0 (TypeError: GreenSSLSocket does not have a public constructor. Instances are returned by SSLContext.wrap_socket().) 的问题。
      • 我尝试使用-l info -c 5 gevent 标志运行并得到unrecognized arguments: gevent。但是它适用于-l info -P gevent。我该如何解决这个问题?
      • 2020 年仍在使用 Win10 + Celery 4.4.7 + Python 3.8.5
      • 2021 年仍在使用 Win10 + Celery 5.1.2 + Python 3.6.8
      【解决方案4】:

      我在 Windows 7 32 位系统上收到此错误。所以我这样做是为了让它发挥作用。

      添加这个

      `os.environ.setdefault('FORKED_BY_MULTIPROCESSING', '1')` 
      

      在您的 django 项目的 myproj/settings.py 文件中定义 celery 实例之前。

      应该喜欢

      os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproj.settings')
      os.environ.setdefault('FORKED_BY_MULTIPROCESSING', '1')
      
      app = Celery('tasks', broker='redis://127.0.0.1:6379/0')
      

      我使用 redis 作为消息传递代理,定义为 broker='redis://127.0.0.1:6379/0'

      【讨论】:

      • 谢谢,这对我有用。会花费几个小时(在已经花费的时间之上)。我只是在尝试 docs.celeryproject.org 中的示例: import os os.environ.setdefault('FORKED_BY_MULTIPROCESSING', '1') app = Celery('tasks', broker='amqp://guest@localhost//' ) 等
      【解决方案5】:

      适用于 Windows 上的 Celery 4.1

      设置环境变量FORKED_BY_MULTIPROCESSING=1。然后你可以简单地运行celery -A &lt;celery module&gt; worker

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-29
        • 1970-01-01
        • 1970-01-01
        • 2023-02-23
        • 2023-03-20
        • 2016-04-10
        • 2016-07-05
        • 2017-09-14
        相关资源
        最近更新 更多