Skip to content

Instantly share code, notes, and snippets.

@ask
Forked from lrvick/get_results.py
Created June 22, 2011 17:37
Show Gist options
  • Save ask/1040634 to your computer and use it in GitHub Desktop.
Save ask/1040634 to your computer and use it in GitHub Desktop.
Get async celery results from subtasks
from tasks import task1
from celery.task import TaskSet
from celery.result import AsyncResult, ResultSet
def get_results(queries):
query_procs = task1.delay(queries).get().join()
results = []
for query_proc in query_procs:
results.extend(query_proc.join())
return results
get_results(['a','b','c'])
from celery.task import task, TaskSet
@task
def task1(queries):
return TaskSet(task2.subtask((query, )) for query in queries).apply_async()
@task
def task2(query):
return TaskSet(task3.subtask() for _ in xrange(20).apply_async()
@task
def task3()
time.sleep(2)
return 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment