Celery Worker命令'包装方法'对象没有属性'__module __'

问题描述 投票:0回答:1

当前正在尝试为我的django应用程序启动一个工作程序,很遗憾,我收到此错误:

  PS C:\Users\User\Documents\Codes\highlightreel> celery -A highlightreel worker -l info
Traceback (most recent call last):
  File "c:\program files\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\program files\python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python38\Scripts\celery.exe\__main__.py", line 7, in <module>
  File "c:\program files\python38\lib\site-packages\celery\__main__.py", line 16, in main
    _main()
  File "c:\program files\python38\lib\site-packages\celery\bin\celery.py", line 322, in main
    cmd.execute_from_commandline(argv)
  File "c:\program files\python38\lib\site-packages\celery\bin\celery.py", line 495, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "c:\program files\python38\lib\site-packages\celery\bin\base.py", line 305, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "c:\program files\python38\lib\site-packages\celery\bin\celery.py", line 487, in handle_argv
    return self.execute(command, argv)
  File "c:\program files\python38\lib\site-packages\celery\bin\celery.py", line 415, in execute
    return cls(
  File "c:\program files\python38\lib\site-packages\celery\bin\worker.py", line 223, in run_from_argv
    return self(*args, **options)
  File "c:\program files\python38\lib\site-packages\celery\bin\base.py", line 253, in __call__
    ret = self.run(*args, **kwargs)
  File "c:\program files\python38\lib\site-packages\celery\bin\worker.py", line 253, in run
    worker = self.app.Worker(
  File "c:\program files\python38\lib\site-packages\celery\worker\worker.py", line 97, in __init__
    self.on_before_init(**kwargs)
  File "c:\program files\python38\lib\site-packages\celery\apps\worker.py", line 93, in on_before_init
    trace.setup_worker_optimizations(self.app, self.hostname)
  File "c:\program files\python38\lib\site-packages\celery\app\trace.py", line 596, in setup_worker_optimizations
    app.finalize()
  File "c:\program files\python38\lib\site-packages\celery\app\base.py", line 538, in finalize
    _announce_app_finalized(self)
  File "c:\program files\python38\lib\site-packages\celery\_state.py", line 54, in _announce_app_finalized
    callback(app)
  File "c:\program files\python38\lib\site-packages\celery\app\__init__.py", line 59, in <lambda>
    lambda app: app._task_from_fun(fun, **options)
  File "c:\program files\python38\lib\site-packages\celery\app\base.py", line 452, in _task_from_fun
    '__header__': staticmethod(head_from_fun(fun, bound=bind)),
  File "c:\program files\python38\lib\site-packages\celery\utils\functional.py", line 279, in head_from_fun
    namespace = {'__name__': fun.__module__}
AttributeError: 'method-wrapper' object has no attribute '__module__'

我正在从项目文件夹中的Powereditor运行此程序。如果我没有在查询中包含项目,该函数就会运行,但这不会呈现任务。

不确定相关内容,但请在下面找到Django代码。

Celery.py

from __future__ import absolute_import, unicode_literals

import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'highlightreel.settings')

app = Celery('highlightreel')

# 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('Request: {0!r}'.format(self.request))

来自settings.py

CELERY_BROKER_URL = 'amqp://localhost'
CELERY_ACCEPT_CONTENT = ['json']
CElERY_TASK_SERIALIZER = 'json'

来自splitter.py

from celery import shared_task

@shared_task
class Splitter():
    def __init__(**kwargs):
        #Variables
django celery django-celery
1个回答
0
投票

根据Iain的评论,问题是我在类而不是函数上使用装饰器@shared_task。

将该任务更改为功能可以初始化该工作程序。

© www.soinside.com 2019 - 2024. All rights reserved.