티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Celery Received unregistered task of type (run example)
Celery에서 (run example) 타입의 등록되지 않은 작업을 수신했습니다.
문제 내용
I'm trying to run example from Celery documentation.
저는 Celery 문서에서 예제를 실행하려고 하고 있습니다.
I run: celeryd --loglevel=INFO
저는 celeryd --loglevel=INFO를 실행했습니다.
/usr/local/lib/python2.7/dist-packages/celery/loaders/default.py:64: NotConfigured: No 'celeryconfig' module found! Please make sure it exists and is available to Python.
"is available to Python." % (configname, )))
[2012-03-19 04:26:34,899: WARNING/MainProcess]
-------------- celery@ubuntu v2.5.1
---- **** -----
--- * *** * -- [Configuration]
-- * - **** --- . broker: amqp://guest@localhost:5672//
- ** ---------- . loader: celery.loaders.default.Loader
- ** ---------- . logfile: [stderr]@INFO
- ** ---------- . concurrency: 4
- ** ---------- . events: OFF
- *** --- * --- . beat: OFF
-- ******* ----
--- ***** ----- [Queues]
-------------- . celery: exchange:celery (direct) binding:celery
tasks.py:
# -*- coding: utf-8 -*-
from celery.task import task
@task
def add(x, y):
return x + y
run_task.py:
# -*- coding: utf-8 -*-
from tasks import add
result = add.delay(4, 4)
print (result)
print (result.ready())
print (result.get())
In same folder celeryconfig.py:
같은 폴더 안에 celeryconfig.py 파일이 있습니다.
CELERY_IMPORTS = ("tasks", )
CELERY_RESULT_BACKEND = "amqp"
BROKER_URL = "amqp://guest:guest@localhost:5672//"
CELERY_TASK_RESULT_EXPIRES = 300
When I run "run_task.py":
"run\_task.py"를 실행하면,
on python console
파이썬 콘솔에서
eb503f77-b5fc-44e2-ac0b-91ce6ddbf153
False
errors on celeryd server
celeryd 서버에서 오류가 발생합니다.
[2012-03-19 04:34:14,913: ERROR/MainProcess] Received unregistered task of type 'tasks.add'.
The message has been ignored and discarded.
Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.
The full contents of the message body was:
{'retries': 0, 'task': 'tasks.add', 'utc': False, 'args': (4, 4), 'expires': None, 'eta': None, 'kwargs': {}, 'id': '841bc21f-8124-436b-92f1-e3b62cafdfe7'}
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer.py", line 444, in receive_message
self.strategies[name](message, body, message.ack_log_error)
KeyError: 'tasks.add'
Please explain what's the problem.
무엇이 문제인지 설명해주세요.
높은 점수를 받은 Solution
I think you need to restart the worker server. I meet the same problem and solve it by restarting.
워커 서버를 다시 시작해야 할 것 같습니다. 같은 문제가 발생하여 다시 시작하여 해결했습니다.
가장 최근 달린 Solution
In my case the issue was, my project was not picking up autodiscover_tasks
properly.
저의 경우 문제는 프로젝트가 autodiscover_tasks를 올바르게 가져오지 못했기 때문입니다.
In celery.py
file the code was for getting autodiscover_tasks
was:
celery.py 파일에서 autodiscover_tasks를 가져 오는 코드는 다음과 같았습니다.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
I changed it to the following one:
저는 다음과 같이 변경했습니다.
from django.apps import apps
app.autodiscover_tasks(lambda: [n.name for n in apps.get_app_configs()])
Best wishes to you.
모든 일들이 순조롭길 바라요!
출처 : https://stackoverflow.com/questions/9769496/celery-received-unregistered-task-of-type-run-example
'개발 > 파이썬' 카테고리의 다른 글
Python에서 pathlib를 사용하여 파일 복사하기 (0) | 2023.01.27 |
---|---|
아주 큰 csv 파일 읽기 (0) | 2023.01.27 |
하나의 데이터 셋에서 테스트와 트레인 샘플 나누어 생성하기 (0) | 2023.01.26 |
내 프로젝트 모듈과 동일 이름의 라이브러리 모듈 사용하기 (0) | 2023.01.26 |
Python의 딕셔너리를 kwargs로 변환하기 (0) | 2023.01.26 |