django - Celery Worker 命令 'method-wrapper' 对象没有属性 '__module__'
问题描述
目前正在尝试为我的 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 代码。
芹菜.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
解决方案
根据 Iain 的评论,问题是我在类而不是函数上使用装饰器 @shared_task。
将此任务更改为函数允许初始化工作程序。
推荐阅读
- python - 完成按熊猫中另一列分组的日期系列并填充缺失的行
- android - android.permission.ACTIVITY_RECOGNITION 在尝试请求用户权限时未被识别
- grpc - grpc_out:protoc-gen-grpc:插件失败,状态码为 1
- python - 只有最后一页的输出被写入 CSV
- python - K-Means 聚类的局限性
- c - 在C中将十进制转换为具有数十亿数字的二进制
- c - 为什么 %p,%x 用字母值给出地址,为什么 %p 用这么多的零(x86)给出任何值;还有为什么 %d 和 %u 说明符不像它们那样工作
- javascript - 需要帮助来弄清楚如何使用 HTML、CSS 和 JavaScript 构建一个简单的游戏
- reactjs - 如何使用reactjs从电话号码中删除+符号
- swift - 如何关闭像 BubbleShowcase 这样的自定义类:UIView?