gpt4 book ai didi

python - celery ,组任务,AttributeError : 'NoneType' object has no attribute 'app'

转载 作者:太空宇宙 更新时间:2023-11-03 12:37:48 25 4
gpt4 key购买 nike

我正在尝试按如下方式运行一组 celery 任务:

@shared_task
def run_sms_task(smstask_id):

smstask = SmsTask.objects.get(id = smstask_id)
if smstask:

phones = []
for user in smstask.userlist.users.all():
phones.append(user.profile.phone)

g = group(send_sms_async(phone, smstask.text) for phone in phones)
g.apply_async()

smstask.status = 3
smstask.save()

任务执行了一部分,最后抛出以下错误:

[2016-11-01 13:42:03,362: ERROR/MainProcess] Task sms_center.tasks.run_sms_task[d575fb59-6b0a-4ea6-851f-0902ef6bd7b9] raised unexpected: AttributeError("'NoneType' object has no attribute 'app'",)
Traceback (most recent call last):
File "/home/alexander/.pyenv/versions/d/lib/python3.5/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/alexander/.pyenv/versions/d/lib/python3.5/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/home/alexander/PycharmProjects/d/sms_center/tasks.py", line 25, in run_sms_task
g.apply_async()
File "/home/alexander/.pyenv/versions/d/lib/python3.5/site-packages/celery/canvas.py", line 502, in apply_async
type = self.type
File "/home/alexander/.pyenv/versions/d/lib/python3.5/site-packages/celery/canvas.py", line 569, in type
return self.app.tasks[self['task']]
File "/home/alexander/.pyenv/versions/d/lib/python3.5/site-packages/celery/canvas.py", line 560, in app
return self._app or (self.tasks[0].app if self.tasks else current_app)
AttributeError: 'NoneType' object has no attribute 'app'

如果您有任何想法,欢迎您提供帮助。谢谢!

最佳答案

我发现了错误。我没有注意到 Group 是从 Subtasks 而不是 Tasks 创建的。那么正确的组创建应该是:

g = group(send_sms_async.s(phone, smstask.text) for phone in phones)

如果您遇到同样的问题,希望这个答案能节省您几分钟时间!

关于python - celery ,组任务,AttributeError : 'NoneType' object has no attribute 'app' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40358560/

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