Python 如何从芹菜链返回第一个任务的结果?
以下是我的任务:Python 如何从芹菜链返回第一个任务的结果?,python,django,celery,Python,Django,Celery,以下是我的任务: @task(name = 'hello') def hello(): print "hello" return "helo" @task(name = 'hey') def hey(resp): print resp 我这样称呼他们:g=celery.chain(hello.s(),hey.s()) 但我希望这样做:hello任务应该返回一个值,不仅返回给任务“hey”,还应该返回一个值。我的意思是,我应该能够在执行完“hello”之后获得返回值。如
@task(name = 'hello')
def hello():
print "hello"
return "helo"
@task(name = 'hey')
def hey(resp):
print resp
我这样称呼他们:g=celery.chain(hello.s(),hey.s())
但我希望这样做:hello任务应该返回一个值,不仅返回给任务“hey”,还应该返回一个值。我的意思是,我应该能够在执行完“hello”之后获得返回值。如何执行?调用链时返回的结果实例将用于链中的最后一个任务,但它将保留对父任务的引用,因此您可以遍历父任务以获取第一个任务:
r = chain(hello.s(), hey.s())()
r.parent.get(timeout=1)
r.parent.parent.get(timeout=1)
first = r
while first.parent:
first = first.parent
请参见调用链时返回的结果实例将用于链中的最后一个任务,但它将保留对父级的引用,因此您可以遍历父级以获取第一个任务:
r = chain(hello.s(), hey.s())()
r.parent.get(timeout=1)
r.parent.parent.get(timeout=1)
first = r
while first.parent:
first = first.parent
看