Django应用程序尚未加载Celery任务

时间:2021-06-15 19:18:14

What is giving the error below? I'm unsure if this is a problem with an app I have installed or one of mine. The exception below is generated only when running Celery i.e. celery -A demo.apps.wall.tasks worker , runserver does not generate any errors. Which app ios the issue?

下面给出错误的是什么?我不确定这是我安装的应用程序或我的应用程序的问题。以下例外仅在运行Celery即celery -A demo.apps.wall.tasks worker时生成,runserver不会生成任何错误。问题是哪个应用程序?

Traceback (most recent call last):
  File "/Users/user/Documents/workspace/demo-api/env/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/celery/__main__.py", line 30, in main
    main()
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/celery/bin/celery.py", line 81, in main
    cmd.execute_from_commandline(argv)
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/celery/bin/celery.py", line 770, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/celery/bin/base.py", line 309, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/celery/bin/base.py", line 469, in setup_app_from_commandline
    self.app = self.find_app(app)
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/celery/bin/base.py", line 489, in find_app
    return find_app(app, symbol_by_name=self.symbol_by_name)
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/celery/app/utils.py", line 238, in find_app
    sym = imp(app)
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
    return imp(module, package=package)
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/user/Documents/workspace/demo-api/demo/apps/Walls/tasks.py", line 14, in <module>
    from demo.apps.Walls.redis_models import WallSchedule, WallBroadcast, UserWalls
  File "/Users/user/Documents/workspace/demo-api/demo/apps/Walls/redis_models.py", line 12, in <module>
    from demo.apps.memberships.models import Membership
  File "/Users/user/Documents/workspace/demo-api/demo/apps/memberships/models.py", line 4, in <module>
    from django.contrib.contenttypes.models import ContentType
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/django/contrib/contenttypes/models.py", line 161, in <module>
    class ContentType(models.Model):
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/django/db/models/base.py", line 94, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
    self.check_apps_ready()
  File "/Users/user/Documents/workspace/demo-api/env/lib/python3.5/site-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Running manage.py check is ok.

运行manage.py检查是可以的。

2 个解决方案

#1


1  

Ok - after posting your celery app files I compared to what I have and tried running. Think I found your issue - it looks like you're calling tasks.py in celery -A demo.apps.wall.tasks.

好的 - 在发布您的芹菜应用程序文件后,我将其与我所拥有的相比并尝试运行。想想我发现了你的问题 - 看起来你正在芹菜中调用tasks.py -A demo.apps.wall.tasks。

If your wall module contains celery.py, and tasks.py - you should call celery -A demo.apps.wall.

如果您的墙模块包含celery.py和tasks.py - 您应该调用celery -A demo.apps.wall。

Here's the directory structure I have, and the celery command I run:

这是我的目录结构,以及我运行的celery命令:

django_project
- an_app
- celery_tasks
   - init.py
   - celery_app.py (celery.py in your case)
   - tasks.py

The command I run: celery worker -A celery_tasks from the django_project directory.

我运行的命令:来自django_project目录的celery worker -A celery_tasks。

#2


6  

Try adding this to the beginning of tasks.py:

尝试将此添加到tasks.py的开头:

import django
django.setup()

#1


1  

Ok - after posting your celery app files I compared to what I have and tried running. Think I found your issue - it looks like you're calling tasks.py in celery -A demo.apps.wall.tasks.

好的 - 在发布您的芹菜应用程序文件后,我将其与我所拥有的相比并尝试运行。想想我发现了你的问题 - 看起来你正在芹菜中调用tasks.py -A demo.apps.wall.tasks。

If your wall module contains celery.py, and tasks.py - you should call celery -A demo.apps.wall.

如果您的墙模块包含celery.py和tasks.py - 您应该调用celery -A demo.apps.wall。

Here's the directory structure I have, and the celery command I run:

这是我的目录结构,以及我运行的celery命令:

django_project
- an_app
- celery_tasks
   - init.py
   - celery_app.py (celery.py in your case)
   - tasks.py

The command I run: celery worker -A celery_tasks from the django_project directory.

我运行的命令:来自django_project目录的celery worker -A celery_tasks。

#2


6  

Try adding this to the beginning of tasks.py:

尝试将此添加到tasks.py的开头:

import django
django.setup()