developer tip

Celery AttributeError : 비동기 오류

copycodes 2020. 12. 27. 11:18
반응형

Celery AttributeError : 비동기 오류


내 Mac (OS / X 10.13.4)에서 로컬로 실행되는 RabbitMQ 및 Celery가 있는데 add.delay (x, y)를 실행할 때 다음 코드가 로컬로 작동합니다.

#!/usr/bin/env python
from celery import Celery
from celery.utils.log import get_task_logger

logger = get_task_logger(__name__)

app = Celery('tasks', \
        broker='pyamqp://appuser:xx@c2/appvhost', \
        backend='db+mysql://appuser:xx@c2/pigpen')

@app.task(bind=True)
def dump_context(self, x, y):
    print('Executing task id {0.id}, args: {0.args!r} kwargs {0.kwargs!r}'.format(self.request))

@app.task
def add(x, y):
    logger.info('Adding {0} + {1}'.format(x, y))
    return x + y

그러나 Kali 2018.2 (현재 업데이트 포함)를 실행하는 ODROID-C2에서 Celery 작업자를 실행하려고하면 실행할 때 다음 오류가 발생합니다 celery -A tasks worker --loglevel=info.

Traceback (most recent call last):
  File "/usr/local/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 14, in main
    _main()
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 326, in main
    cmd.execute_from_commandline(argv)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 488, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 281, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 480, in handle_argv
    return self.execute(command, argv)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 412, in execute
    ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/worker.py", line 221, in run_from_argv
    return self(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 244, in __call__
    ret = self.run(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/worker.py", line 255, in run
    **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/worker.py", line 99, in __init__
    self.setup_instance(**self.prepare_args(**kwargs))
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/worker.py", line 122, in setup_instance
    self.should_use_eventloop() if use_eventloop is None
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/worker.py", line 241, in should_use_eventloop
    self._conninfo.transport.implements.async and
  File "/home/autossh/.local/lib/python2.7/site-packages/kombu/transport/base.py", line 125, in __getattr__
    raise AttributeError(key)
AttributeError: async

Kali ODROID에서 Python Pika 스크립트를 사용하여 c2라는 호스트의 RabbitMQ 인스턴스에 연결할 수 있으며 해당 장치의 mysql은 c2 컴퓨터에서도 작동합니다. 비슷한 오류를 발견했지만 해당 솔루션 중 어느 것도 나를 위해 일하지 않았습니다.

pip를 통해 ODROID-C2에 설치된 셀러리 버전은 다음과 같습니다.

celery --version
4.1.0 (latentcall)

celery == 4.1.1로 업데이트하여 정렬했습니다.

4.1.X의 최신 릴리스가 kombu에서 모듈 이름 변경을 분류 한 것 같습니다.


Kombu 4.1.0을 사용하고 있는지 확인하십시오. 최신 버전의 Kombu는 비동기 이름을 비동기로 바꿉니다.


Celery does not pin its requirements for kombu and billiard to specific versions. They require the following:

billiard>=3.5.0.2,<3.6.0
kombu>=4.0.2,<5.0

https://github.com/celery/celery/blob/v4.1.0/requirements/default.txt

kombu 4.2.0 was released with a breaking change and previous versions of celery automatically install it.

Since Celery doesn't pin specific versions, you should pin to the following if you will continue to use celery 4.1.0:

kombu==4.1.0
billiard==3.5.0.2

pip install --upgrade 'celery>=4.2.0rc4'

kombu==4.2.0 renames async to asynchronous, celery fixed it in celery==4.2.0rc4.

So you should upgrade celery to 4.2.0rc4.

refer: https://github.com/celery/celery/commit/c8ef7ad60b72a194654c58beb04a1d65cd0435ad


That was the issue, it was in fact the kombu version.

I managed to get 2 versions of kombu installed, 4.2.0 as the 'appuser' user, which I was trying to start the worker under, and 4.1.0 as 'root'. The 4.1.0 as 'root' would work, the other user did not.

I removed kombu 4.2.0 from the 'appuser' user account (pip uninstall kombu as that user), so it would use the system-wide installed package, and the Celery worker operated correctly under that account.

To verify that it is in fact kombu 4.2.0 that breaks, I removed the system-wide 4.1.0 version and let pip install the latest version, which it gets as 4.2.0, and the Celery worker would no longer start. I uninstalled it and forced pip to install 4.1.0 (pip install kombu==4.1.0) and the worker operated correctly.

As another check I went to my Mac, where I originally wrote/tested this code, and checked the kombu version installed there by pip: 4.1.0. I'm not sure why pip on the Mac and Pi3 installed the 4.1.0 version of kombu while pip on the ODROID-C2 installed the 4.2.0 version. I'll dig more if I get a chance but it works now.


A quick hack fix is to disable the result backend:

# CELERY_RESULT_BACKEND = 'redis://redis'

ReferenceURL : https://stackoverflow.com/questions/50444988/celery-attributeerror-async-error

반응형