gpt4 book ai didi

python - RuntimeError : 'list' must be None or a list, not while trying to start celery worker

转载 作者:太空狗 更新时间:2023-10-29 17:00:02 28 4
gpt4 key购买 nike

我正在尝试在关注 First Steps With Django 时添加 celery 任务但我收到以下错误:

Traceback (most recent call last):
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/bin/celery", line 11, in <module>
sys.exit(main())
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/__main__.py", line 30, in main
main()
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/bin/celery.py", line 770, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/bin/base.py", line 311, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/bin/celery.py", line 762, in handle_argv
return self.execute(command, argv)
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/bin/celery.py", line 694, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/bin/worker.py", line 179, in run_from_argv
return self(*args, **options)
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/bin/base.py", line 274, in __call__
ret = self.run(*args, **kwargs)
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/bin/worker.py", line 212, in run
state_db=self.node_format(state_db, hostname), **kwargs
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/worker/__init__.py", line 95, in __init__
self.app.loader.init_worker()
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/loaders/base.py", line 128, in init_worker
self.import_default_modules()
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/loaders/base.py", line 116, in import_default_modules
signals.import_modules.send(sender=self.app)
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/utils/dispatch/signal.py", line 166, in send
response = receiver(signal=self, sender=sender, **named)
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/amqp/utils.py", line 42, in __call__
self.set_error_state(exc)
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/amqp/utils.py", line 39, in __call__
**dict(self.kwargs, **kwargs) if self.kwargs else kwargs
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/app/base.py", line 330, in _autodiscover_tasks
self.loader.autodiscover_tasks(packages, related_name)
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/loaders/base.py", line 252, in autodiscover_tasks
related_name) if mod)
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/loaders/base.py", line 273, in autodiscover_tasks
return [find_related_module(pkg, related_name) for pkg in packages]
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/loaders/base.py", line 273, in <listcomp>
return [find_related_module(pkg, related_name) for pkg in packages]
File "/Users/amrullahzunzunia/virtualenvs/flyrobe_new/lib/python3.5/site-packages/celery/loaders/base.py", line 295, in find_related_module
_imp.find_module(related_name, pkg_path)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 270, in find_module
"not {}".format(type(name)))
RuntimeError: 'list' must be None or a list, not <class 'str'>

这是我的项目结构:

  • 项目
    • 配置
      • 设置
        • 基础.py
        • 本地.py
        • 生产.py
      • celery.py # 有一个 celery 应用程序
      • urls.py
      • wsgi.py
    • 杂项
      • 模型.py
      • views.py
      • tasks.py # 有一个 celery 任务

这是我的 config/celery.py:

from __future__ import absolute_import
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local')

from django.conf import settings

app = Celery('config')

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))

这是我的 config/settings/base.py:

THIRD_PARTY_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
'django.contrib.gis',
'oauth2_provider',
'rest_framework',
'rest_framework_gis',
'import_export',
'braces',
'social.apps.django_app.default',
'rest_framework_social_oauth2',
]

CUSTOM_APPS = [
'miscellaneous',
# more apps
]

INSTALLED_APPS = THIRD_PARTY_APPS + CUSTOM_APPS

BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Kolkata'

这是我的 config/settings/local.py:

from .base import *
LOCAL_APPS = [
'debug_toolbar',
]
INSTALLED_APPS.extend(LOCAL_APPS)

这是我的 miscellaneous/tasks.py:

from celery import shared_task

@shared_task
def log_request_meta(request_meta):
# this is not complete yet
return {"a": "b"}

我正在使用 python-3.5 和 django 1.9。我无法弄清楚我错过了什么或哪里错了,因为我完全按照上面提到的教程做了。

更新:Celery 版本是 3.1.20

最佳答案

我是这样解决问题的:

我看到我的一个应用程序缺少 __init__.py,这导致 app.autodiscover_tasks(settings.INSTALLED_APPS) 出现问题

我添加了缺少的 __init__.py 并且 celery worker 开始时没有任何问题

关于python - RuntimeError : 'list' must be None or a list, not <class 'str' > while trying to start celery worker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35838989/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com