我一直在与一个芹菜工人一起运行Flask应用程序,并在三个分离的Docker容器中运行Redis,没有任何问题。
这是我的启动方式:
celery worker -A app.controller.engine.celery -l info --concurrency=2 --pool eventlet
芹菜开始运转良好
-------------- 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)
我评论了对我的实际代码的调用,只是为了验证我没有把我的模块代码弄乱了。。但是它还是崩溃了。
任何人都知道什么地方可能出问题或如何正确调试它?
非常感谢
答案 0 :(得分:18)
问题是我的celery容器在构建时使用pip下载了redis软件包的新版本,最终导致bug或严重的更改,当celery在连接到redis时尝试使用它时,崩溃了。这个新的redis库是3.0.0,并于今天发布。
要解决此问题,您必须在requirements.txt(即2.10.6)中指定以前的版本。
实际上,在requirements.txt文件中指定软件包版本是防止此类问题的一种好习惯。
答案 1 :(得分:2)
我今天也遇到了同样的问题。希望这可以在Celery的更新中很快得到解决。我也恢复了以前的版本。
答案 2 :(得分:2)
没有足够的代表发表评论:
此问题由芹菜人们在以下位置进行跟踪: https://github.com/celery/celery/issues/5175
此PR的领导者: https://github.com/celery/celery/pull/5176
已被合并和还原。因为其他一些修复程序降落了。我不确定是否可以解决问题。对我来说不再重要了。
答案 3 :(得分:1)
对于使用docker-airflow的任何人,我使用的是puckel/docker-airflow
只需添加
&& 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 dockerfile来修复此错误,请参见here