我在尝试使用和弦在发送完所有任务后发送任务时出错。
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/wenzhixue/projects/workspace/fallfor_core/twitter/tasks.py", line 13, in bulk_change_bio
chord([change_bio_task.delay(account,'http://fallfor.com') for account in account_list ])(shutdown.s(c))
File "/Library/Python/2.7/site-packages/celery/canvas.py", line 470, in __call__
_chord = self.type
File "/Library/Python/2.7/site-packages/celery/canvas.py", line 467, in type
return self._type or self.tasks[0].type.app.tasks['celery.chord']
AttributeError: 'AsyncResult' object has no attribute 'type'
-
@task()
def shutdown(ec2):
print "shutting down!!!!"
time.sleep(300)
return True
c = Ec2()
account_list = Account.objects.all()
chord([change_bio_task.delay() for account in account_list ])(shutdown.s(c))
答案 0 :(得分:4)
Chord接受两个参数:第一个子任务列表被称为一个组,第二个可选子是在列表中的整个任务完成后用作回调的子任务。
res = chord([add.s(2, 2), add.s(4, 4)])(sum_task.s())
在您的代码中,您将作为AsyncResults的第一个参数列表而不是子任务传递。 这应该是正确的:
chord([change_bio_task.s() for account in account_list ])(shutdown.si(c))
看一下我将shutdown.s(c)
更改为shutdown.si(c)
这是不可变的,并忽略返回已完成change_bio_task
的结果。