Celery CRITICAL/MainProcess] Unrecoverable error: AttributeError("'float' object has no attribute 'items'",)

Celery CRITICAL/MainProcess] Unrecoverable error: AttributeError("'float' object has no attribute 'items'",)

我已经 运行 一个带有 celery worker 和 redis 的烧瓶应用程序在三个分开的 docker 容器中,没有任何问题。

我是这样开始的:

celery worker -A app.controller.engine.celery -l info --concurrency=2 --pool eventlet

Celery 开始正常:

 -------------- celery@a828bd5b0089 v4.2.1 (windowlicker)
---- **** -----
--- * ***  * -- Linux-4.9.93-linuxkit-aufs-x86_64-with 2018-11-15 16:06:59
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app:         app.controller.engine:0x7f8ba4eb70b8
- ** ---------- .> transport:   redis://redis:6379/0
- ** ---------- .> results:     redis://redis:6379/1
- *** --- * --- .> concurrency: 2 (eventlet)
-- ******* ---- .> task events: ON
--- ***** -----
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery


[tasks]
  . app.controller.engine.do

INFO:engineio:Server initialized for eventlet.
INFO:engineio:Server initialized for threading.
[2018-11-15 15:44:34,301: INFO/MainProcess] Connected to redis://redis:6379/0
[2018-11-15 15:44:34,321: INFO/MainProcess] mingle: searching for neighbors
[2018-11-15 15:44:35,358: INFO/MainProcess] mingle: all alone
[2018-11-15 15:44:35,396: INFO/MainProcess] pidbox: Connected to redis://redis:6379/0.
[2018-11-15 15:44:35,415: INFO/MainProcess] celery@12af03844cd0 ready.

但是在启动任务的时候,突然崩溃了:

[2018-11-15 15:02:03,224: CRITICAL/MainProcess] Unrecoverable error: AttributeError("'float' object has no attribute 'items'",)
Traceback (most recent call last):
  File "/app/env/lib/python3.6/site-packages/celery/worker/worker.py", line 205, in start
    self.blueprint.start(self)
  File "/app/env/lib/python3.6/site-packages/celery/bootsteps.py", line 119, in start
    step.start(parent)
  File "/app/env/lib/python3.6/site-packages/celery/bootsteps.py", line 369, in start
    return self.obj.start()
  File "/app/env/lib/python3.6/site-packages/celery/worker/consumer/consumer.py", line 317, in start
    blueprint.start(self)
  File "/app/env/lib/python3.6/site-packages/celery/bootsteps.py", line 119, in start
    step.start(parent)
  File "/app/env/lib/python3.6/site-packages/celery/worker/consumer/consumer.py", line 593, in start
    c.loop(*c.loop_args())
  File "/app/env/lib/python3.6/site-packages/celery/worker/loops.py", line 121, in synloop
    connection.drain_events(timeout=2.0)
  File "/app/env/lib/python3.6/site-packages/kombu/connection.py", line 301, in drain_events
    return self.transport.drain_events(self.connection, **kwargs)
  File "/app/env/lib/python3.6/site-packages/kombu/transport/virtual/base.py", line 963, in drain_events
    get(self._deliver, timeout=timeout)
  File "/app/env/lib/python3.6/site-packages/kombu/transport/redis.py", line 359, in get
    ret = self.handle_event(fileno, event)
  File "/app/env/lib/python3.6/site-packages/kombu/transport/redis.py", line 341, in handle_event
    return self.on_readable(fileno), self
  File "/app/env/lib/python3.6/site-packages/kombu/transport/redis.py", line 337, in on_readable
    chan.handlers[type]()
  File "/app/env/lib/python3.6/site-packages/kombu/transport/redis.py", line 724, in _brpop_read
    self.connection._deliver(loads(bytes_to_str(item)), dest)
  File "/app/env/lib/python3.6/site-packages/kombu/transport/virtual/base.py", line 983, in _deliver
    callback(message)
  File "/app/env/lib/python3.6/site-packages/kombu/transport/virtual/base.py", line 632, in _callback
    self.qos.append(message, message.delivery_tag)
  File "/app/env/lib/python3.6/site-packages/kombu/transport/redis.py", line 149, in append
    pipe.zadd(self.unacked_index_key, time(), delivery_tag) \
  File "/app/env/lib/python3.6/site-packages/redis/client.py", line 2263, in zadd
    for pair in iteritems(mapping):
  File "/app/env/lib/python3.6/site-packages/redis/_compat.py", line 123, in iteritems
    return iter(x.items())
AttributeError: 'float' object has no attribute 'items'

我在堆栈跟踪中没有看到对我的代码的任何引用。

这是任务方法:

@celery.task()
def do(module_name, json_input):
    logger.info('____ Running _________________________')
    logger.info('testing ***********************')
    #modules.run(module_name, json_input)

我评论了对我的实际代码的调用,只是为了验证我没有将它与我的模块代码搞混。但它还是崩溃了。

有人知道可能出了什么问题或如何正确调试它吗?

非常感谢

问题是我的 celery 容器在构建时使用 pip 下载了新版本的 redis 包,最终出现错误或严重更改,当 celery 在连接到 redis 时尝试使用它时崩溃。这个新的 redis 库是 3.0.0,今天发布了。

要解决此问题,您必须在 requirements.txt(即 2.10.6)中指定以前的版本。

实际上,在 requirements.txt 中指定包版本是防止此类问题的好习惯。

我今天 运行 遇到了同样的问题。希望这在 Celery 的更新中很快得到解决。我也恢复到以前的版本了。

还没有足够的代表发表评论:

这个问题由 celery 人员跟踪: https://github.com/celery/celery/issues/5175

导致此 PR: https://github.com/celery/celery/pull/5176

已合并并还原。因为其他一些修复程序着陆了。我不确定这是否解决了它。它不再与我相关。

对于使用 docker-airflow 的任何人,我使用了 puckel/docker-airflow 的人 只需修改 docker 文件,添加

   && pip install 'redis>=2.10.5,<3'\

通过在 apache-airflow 内置模块中添加芹菜,仅将 celery[redis] 替换为 celery,即

  && pip install apache-airflow[crypto,celery,postgres,hive,jdbc,mysql]==$AIRFLOW_VERSION 

更新: 他们最近还更改了 docker-airflow docker 文件以修复此错误,请参阅 here