Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从芹菜链返回第一个任务的结果?_Python_Django_Celery - Fatal编程技术网

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