遵循以下文档后无法运行Django Celery

时间:2019-05-06 18:09:54

标签: python django celery django-celery djcelery

我正在尝试将芹菜应用于当前正在进行的django 2项目。我正在使用Django 2.13和芹菜4.3。此处 init .py中的代码:

import os
from celery import Celery

CONFIG_SETTING = 'lp.settings.development_test'
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', CONFIG_SETTING)

app = Celery('myproject')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print('hello world')

这是基本设置中的代码:


CELERY_BROKER_URL = 'amqp://guest:guest@localhost//'

#: Only add pickle to this list if your broker is secured
#: from unwanted access (see userguide/security.html)
CELERY_ACCEPT_CONTENT = ['json']
CELERY_RESULT_BACKEND = 'django-db'
CELERY_TASK_SERIALIZER = 'json'
CELERY_CACHE_BACKEND = 'django-cache'

INSTALLED_APPS = [
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

     ...

    'django.contrib.auth',
    'django.contrib.admin',
    'django_celery_results',
]

我跑步时

celery -A myproject worker -l info

我得到一个错误。这是整个堆栈跟踪:


[2019-05-06 16:09:43,658: CRITICAL/MainProcess] Unrecoverable error: TypeError("argument of type 'NoneType' is not iterable")
Traceback (most recent call last):
  File "c:\program files\python37\lib\site-packages\celery\worker\worker.py", line 205, in start
    self.blueprint.start(self)
  File "c:\program files\python37\lib\site-packages\celery\bootsteps.py", line 119, in start
    step.start(parent)
  File "c:\program files\python37\lib\site-packages\celery\bootsteps.py", line 369, in start
    return self.obj.start()
  File "c:\program files\python37\lib\site-packages\celery\concurrency\base.py", line 131, in start
    self.on_start()
  File "c:\program files\python37\lib\site-packages\celery\concurrency\prefork.py", line 112, in on_start
    **self.options)
  File "c:\program files\python37\lib\site-packages\billiard\pool.py", line 1010, in __init__
    self._create_worker_process(i)
  File "c:\program files\python37\lib\site-packages\billiard\pool.py", line 1119, in _create_worker_process
    w.start()
  File "c:\program files\python37\lib\site-packages\billiard\process.py", line 124, in start
    self._popen = self._Popen(self)
  File "c:\program files\python37\lib\site-packages\billiard\context.py", line 383, in _Popen
    return Popen(process_obj)
  File "c:\program files\python37\lib\site-packages\billiard\popen_spawn_win32.py", line 47, in __init__
    spawn._Django_old_layout_hack__save()
  File "c:\program files\python37\lib\site-packages\billiard\spawn.py", line 81, in _Django_old_layout_hack__save
    project_dir = os.path.normpath(_module_parent_dir(project))
  File "c:\program files\python37\lib\site-packages\billiard\spawn.py", line 53, in _module_parent_dir
    dir, filename = os.path.split(_module_dir(mod))
  File "c:\program files\python37\lib\site-packages\billiard\spawn.py", line 60, in _module_dir
    if '__init__.py' in mod.__file__:
TypeError: argument of type 'NoneType' is not iterable

关于我在做什么错的任何想法吗?

RabbitMQ作为服务运行。

谢谢!

0 个答案:

没有答案