This document describes the current stable version of Celery (3.1). For development docs, go here.

celery.result

celery.result

Task results/state and groups of results.

class celery.result.ResultBase[source]

Base class for all results

parent = None

Parent result (if part of a chain)

class celery.result.AsyncResult(id, backend=None, task_name=None, app=None, parent=None)[source]

Query task state.

Parameters:
exception TimeoutError

Error raised for timeouts.

app = None
as_tuple()[source]
backend = None

The task result backend to use.

build_graph(intermediate=False, formatter=None)[source]
children
collect(intermediate=False, **kwargs)[source]

Iterator, like get() will wait for the task to complete, but will also follow AsyncResult and ResultSet returned by the task, yielding (result, value) tuples for each result in the tree.

An example would be having the following tasks:

from celery import group
from proj.celery import app

@app.task(trail=True)
def A(how_many):
    return group(B.s(i) for i in range(how_many))()

@app.task(trail=True)
def B(i):
    return pow2.delay(i)

@app.task(trail=True)
def pow2(i):
    return i ** 2

Note that the trail option must be enabled so that the list of children is stored in result.children. This is the default but enabled explicitly for illustration.

Calling collect() would return:

>>> from celery.result import ResultBase
>>> from proj.tasks import A

>>> result = A.delay(10)
>>> [v for v in result.collect()
...  if not isinstance(v, (ResultBase, tuple))]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
failed()[source]

Returns True if the task failed.

forget()[source]

Forget about (and possibly remove the result of) this task.

get(timeout=None, propagate=True, interval=0.5, no_ack=True, follow_parents=True, EXCEPTION_STATES=frozenset(['FAILURE', 'RETRY', 'REVOKED']), PROPAGATE_STATES=frozenset(['FAILURE', 'REVOKED']))[source]

Wait until task is ready, and return its result.

Warning

Waiting for tasks within a task may lead to deadlocks. Please read Avoid launching synchronous subtasks.

Parameters:
  • timeout – How long to wait, in seconds, before the operation times out.
  • propagate – Re-raise exception if the task failed.
  • interval – Time to wait (in seconds) before retrying to retrieve the result. Note that this does not have any effect when using the amqp result store backend, as it does not use polling.
  • no_ack – Enable amqp no ack (automatically acknowledge message). If this is False then the message will not be acked.
  • follow_parents – Reraise any exception raised by parent task.
Raises:

celery.exceptions.TimeoutError – if timeout is not None and the result does not arrive within timeout seconds.

If the remote call raised an exception then that exception will be re-raised.

get_leaf()[source]
graph[source]
id = None

The task’s UUID.

info

When the task has been executed, this contains the return value. If the task raised an exception, this will be the exception instance.

iterdeps(intermediate=False)[source]
maybe_reraise()[source]
ready()[source]

Returns True if the task has been executed.

If the task is still running, pending, or is waiting for retry then False is returned.

result

When the task has been executed, this contains the return value. If the task raised an exception, this will be the exception instance.

revoke(connection=None, terminate=False, signal=None, wait=False, timeout=None)[source]

Send revoke signal to all workers.

Any worker receiving the task, or having reserved the task, must ignore it.

Parameters:
  • terminate – Also terminate the process currently working on the task (if any).
  • signal – Name of signal to send to process if terminate. Default is TERM.
  • wait – Wait for replies from workers. Will wait for 1 second by default or you can specify a custom timeout.
  • timeout – Time in seconds to wait for replies if wait enabled.
serializable()
state

The tasks current state.

Possible values includes:

PENDING

The task is waiting for execution.

STARTED

The task has been started.

RETRY

The task is to be retried, possibly because of failure.

FAILURE

The task raised an exception, or has exceeded the retry limit. The result attribute then contains the exception raised by the task.

SUCCESS

The task executed successfully. The result attribute then contains the tasks return value.
status

The tasks current state.

Possible values includes:

PENDING

The task is waiting for execution.

STARTED

The task has been started.

RETRY

The task is to be retried, possibly because of failure.

FAILURE

The task raised an exception, or has exceeded the retry limit. The result attribute then contains the exception raised by the task.

SUCCESS

The task executed successfully. The result attribute then contains the tasks return value.
successful()[source]

Returns True if the task executed successfully.

supports_native_join
task_id

compat alias to id

traceback

Get the traceback of a failed task.

wait(timeout=None, propagate=True, interval=0.5, no_ack=True, follow_parents=True, EXCEPTION_STATES=frozenset(['FAILURE', 'RETRY', 'REVOKED']), PROPAGATE_STATES=frozenset(['FAILURE', 'REVOKED']))

Wait until task is ready, and return its result.

Warning

Waiting for tasks within a task may lead to deadlocks. Please read Avoid launching synchronous subtasks.

Parameters:
  • timeout – How long to wait, in seconds, before the operation times out.
  • propagate – Re-raise exception if the task failed.
  • interval – Time to wait (in seconds) before retrying to retrieve the result. Note that this does not have any effect when using the amqp result store backend, as it does not use polling.
  • no_ack – Enable amqp no ack (automatically acknowledge message). If this is False then the message will not be acked.
  • follow_parents – Reraise any exception raised by parent task.
Raises:

celery.exceptions.TimeoutError – if timeout is not None and the result does not arrive within timeout seconds.

If the remote call raised an exception then that exception will be re-raised.

class celery.result.ResultSet(results, app=None, **kwargs)[source]

Working with more than one result.

Parameters:results – List of result instances.
add(result)[source]

Add AsyncResult as a new member of the set.

Does nothing if the result is already a member.

app = None
backend
clear()[source]

Remove all results from this set.

completed_count()[source]

Task completion count.

Returns:the number of tasks completed.
discard(result)[source]

Remove result from the set if it is a member.

If it is not a member, do nothing.

failed()[source]

Did any of the tasks fail?

Returns:True if one of the tasks failed. (i.e., raised an exception)
forget()[source]

Forget about (and possible remove the result of) all the tasks.

get(timeout=None, propagate=True, interval=0.5, callback=None, no_ack=True)[source]

See join()

This is here for API compatibility with AsyncResult, in addition it uses join_native() if available for the current result backend.

iter_native(timeout=None, interval=0.5, no_ack=True)[source]

Backend optimized version of iterate().

New in version 2.2.

Note that this does not support collecting the results for different task types using different backends.

This is currently only supported by the amqp, Redis and cache result backends.

iterate(*args, **kwargs)[source]

Deprecated method, use get() with a callback argument.

join(timeout=None, propagate=True, interval=0.5, callback=None, no_ack=True)[source]

Gathers the results of all tasks as a list in order.

Note

This can be an expensive operation for result store backends that must resort to polling (e.g. database).

You should consider using join_native() if your backend supports it.

Warning

Waiting for tasks within a task may lead to deadlocks. Please see Avoid launching synchronous subtasks.

Parameters:
  • timeout – The number of seconds to wait for results before the operation times out.
  • propagate – If any of the tasks raises an exception, the exception will be re-raised.
  • interval – Time to wait (in seconds) before retrying to retrieve a result from the set. Note that this does not have any effect when using the amqp result store backend, as it does not use polling.
  • callback – Optional callback to be called for every result received. Must have signature (task_id, value) No results will be returned by this function if a callback is specified. The order of results is also arbitrary when a callback is used. To get access to the result object for a particular id you will have to generate an index first: index = {r.id: r for r in gres.results.values()} Or you can create new result objects on the fly: result = app.AsyncResult(task_id) (both will take advantage of the backend cache anyway).
  • no_ack – Automatic message acknowledgement (Note that if this is set to False then the messages will not be acknowledged).
Raises:

celery.exceptions.TimeoutError – if timeout is not None and the operation takes longer than timeout seconds.

join_native(timeout=None, propagate=True, interval=0.5, callback=None, no_ack=True)[source]

Backend optimized version of join().

New in version 2.2.

Note that this does not support collecting the results for different task types using different backends.

This is currently only supported by the amqp, Redis and cache result backends.

maybe_reraise()[source]
ready()[source]

Did all of the tasks complete? (either by success of failure).

Returns:True if all of the tasks has been executed.
remove(result)[source]

Remove result from the set; it must be a member.

Raises:KeyError – if the result is not a member.
results = None

List of results in in the set.

revoke(connection=None, terminate=False, signal=None, wait=False, timeout=None)[source]

Send revoke signal to all workers for all tasks in the set.

Parameters:
  • terminate – Also terminate the process currently working on the task (if any).
  • signal – Name of signal to send to process if terminate. Default is TERM.
  • wait – Wait for replies from worker. Will wait for 1 second by default or you can specify a custom timeout.
  • timeout – Time in seconds to wait for replies if wait enabled.
subtasks

Deprecated alias to results.

successful()[source]

Was all of the tasks successful?

Returns:True if all of the tasks finished successfully (i.e. did not raise an exception).
supports_native_join
update(results)[source]

Update set with the union of itself and an iterable with results.

waiting()[source]

Are any of the tasks incomplete?

Returns:True if one of the tasks are still waiting for execution.
class celery.result.GroupResult(id=None, results=None, **kwargs)[source]

Like ResultSet, but with an associated id.

This type is returned by group, and the deprecated TaskSet, meth:~celery.task.TaskSet.apply_async method.

It enables inspection of the tasks state and return values as a single entity.

Parameters:
  • id – The id of the group.
  • results – List of result instances.
as_tuple()[source]
children
delete(backend=None)[source]

Remove this result if it was previously saved.

id = None

The UUID of the group.

classmethod restore(id, backend=None)[source]

Restore previously saved group result.

results = None

List/iterator of results in the group

save(backend=None)[source]

Save group-result for later retrieval using restore().

Example:

>>> def save_and_restore(result):
...     result.save()
...     result = GroupResult.restore(result.id)
serializable()
class celery.result.EagerResult(id, ret_value, state, traceback=None)[source]

Result that we know has already been executed.

forget()[source]
get(timeout=None, propagate=True, **kwargs)[source]
ready()[source]
result

The tasks return value

revoke(*args, **kwargs)[source]
state

The tasks state.

status

The tasks state.

supports_native_join
task_name = None
traceback

The traceback if the task failed.

wait(timeout=None, propagate=True, **kwargs)
celery.result.result_from_tuple(r, app=None)[source]