Celery CRITICAL/MainProcess] 不可恢复的错误:AttributeError("'float' object has no attribute 'items'&qu
Posted
技术标签:
【中文标题】Celery CRITICAL/MainProcess] 不可恢复的错误:AttributeError("\'float\' object has no attribute \'items\'",)【英文标题】:Celery CRITICAL/MainProcess] Unrecoverable error: AttributeError("'float' object has no attribute 'items'",)Celery CRITICAL/MainProcess] 不可恢复的错误:AttributeError("'float' object has no attribute 'items'",) 【发布时间】:2019-04-18 17:32:55 【问题描述】:我一直在三个独立的 docker 容器中运行带有 celery worker 和 redis 的烧瓶应用程序,没有任何问题。
我是这样开始的:
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)
我评论了对我的实际代码的调用,只是为了验证我没有把它与我的模块代码搞混。但无论如何它都会崩溃。
任何人都知道可能出了什么问题或如何正确调试它?
非常感谢
【问题讨论】:
【参考方案1】:还没有足够的代表发表评论:
celery 人员在以下方面跟踪了此问题: https://github.com/celery/celery/issues/5175
导致此 PR: https://github.com/celery/celery/pull/5176
已合并和还原。因为其他一些修复登陆。我不确定这是否解决了它。它与我不再相关。
【讨论】:
这不是评论 XD:)【参考方案2】:对于任何使用 docker-airflow 的人,我使用了 puckel/docker-airflow
的人
只需要修改dockerfile添加
&& pip install 'redis>=2.10.5,<3'\
只用celery
替换celery[redis]
,通过在apache-airflow内置模块中添加芹菜,即,
&& pip install apache-airflow[crypto,celery,postgres,hive,jdbc,mysql]==$AIRFLOW_VERSION
更新: 他们最近还更改了 docker-airflow dockerfile 以修复此错误,请参阅here
【讨论】:
【参考方案3】:我今天遇到了同样的问题。希望这会在 Celery 的更新中很快得到解决。我也恢复到以前的版本。
【讨论】:
【参考方案4】:问题是我的 celery 容器在构建时使用 pip 下载了新版本的 redis 包,最终出现了一个错误或严重的更改,当 celery 在连接到 redis 时尝试使用它时崩溃。这个新的redis库是3.0.0,今天发布了。
要解决此问题,您必须在 requirements.txt 中指定以前的版本(即 2.10.6)。
实际上,在 requirements.txt 中指定包版本是防止此类问题的好习惯。
【讨论】:
非常感谢! 你才是真正的MVP!以上是关于Celery CRITICAL/MainProcess] 不可恢复的错误:AttributeError("'float' object has no attribute 'items'&qu的主要内容,如果未能解决你的问题,请参考以下文章