celery.result — Celery 5.5.2 documentation (original) (raw)

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

Task results/state and results for groups of tasks.

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

Query task state.

Parameters:

exception TimeoutError

The operation timed out.

app = None

property args

as_list()[source]

Return as a list of task IDs.

as_tuple()[source]

backend = None

The task result backend to use.

build_graph(intermediate=False, formatter=None)[source]

property children

collect(intermediate=False, **kwargs)[source]

Collect results as they return.

Iterator, like get() will wait for the task to complete, but will also follow AsyncResult and ResultSetreturned 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

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]

Note

The Task.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.

Yields:

Tuple[AsyncResult, Any] – tuples containing the result instance of the child task, and the return value of that task.

property date_done

UTC date and time.

failed()[source]

Return True if the task failed.

forget()[source]

Forget the result of this task and its parents.

get(timeout=None, propagate=True, interval=0.5, no_ack=True, follow_parents=True, callback=None, on_message=None, on_interval=None, disable_sync_subtasks=True, EXCEPTION_STATES=frozenset({'FAILURE', 'RETRY', 'REVOKED'}), PROPAGATE_STATES=frozenset({'FAILURE', 'REVOKED'}))[source]

Wait until task is ready, and return its result.

Warning

Backends use resources to store and transmit results. To ensure that resources are released, you must eventually callget() or forget() on EVERY AsyncResult instance returned after calling a task.

Parameters:

Raises:

get_leaf()[source]

property graph

id = None

The task’s UUID.

property ignored

If True, task result retrieval is disabled.

property info

Task return value.

Note

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]

property kwargs

maybe_reraise(propagate=True, callback=None)

maybe_throw(propagate=True, callback=None)[source]

property name

property queue

ready()[source]

Return True if the task has executed.

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

property result

Task return value.

Note

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

property retries

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:

Send revoke signal to all workers only for tasks with matching headers values.

Any worker receiving the task, or having reserved the task, must ignore it. All header fields must match.

Parameters:

property 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.

property 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]

Return True if the task executed successfully.

property supports_native_join

property task_id

Compat. alias to id.

then(callback, on_error=None, weak=False)[source]

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

property traceback

Get the traceback of a failed task.

wait(timeout=None, propagate=True, interval=0.5, no_ack=True, follow_parents=True, callback=None, on_message=None, on_interval=None, disable_sync_subtasks=True, EXCEPTION_STATES=frozenset({'FAILURE', 'RETRY', 'REVOKED'}), PROPAGATE_STATES=frozenset({'FAILURE', 'REVOKED'}))

Wait until task is ready, and return its result.

Warning

Backends use resources to store and transmit results. To ensure that resources are released, you must eventually callget() or forget() on EVERY AsyncResult instance returned after calling a task.

Parameters:

Raises:

property worker

class celery.result.EagerResult(id, ret_value, state, traceback=None, name=None)[source]

Result that we know has already been executed.

forget()[source]

Forget the result of this task and its parents.

get(timeout=None, propagate=True, disable_sync_subtasks=True, **kwargs)[source]

Wait until task is ready, and return its result.

Warning

Backends use resources to store and transmit results. To ensure that resources are released, you must eventually callget() or forget() on EVERY AsyncResult instance returned after calling a task.

Parameters:

Raises:

ready()[source]

Return True if the task has executed.

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

property result

The tasks return value.

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

Send revoke signal to all workers.

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

Parameters:

property state

The tasks state.

property status

The tasks state.

property supports_native_join

then(callback, on_error=None, weak=False)[source]

property traceback

The traceback if the task failed.

wait(timeout=None, propagate=True, disable_sync_subtasks=True, **kwargs)

Wait until task is ready, and return its result.

Warning

Backends use resources to store and transmit results. To ensure that resources are released, you must eventually callget() or forget() on EVERY AsyncResult instance returned after calling a task.

Parameters:

Raises:

class celery.result.GroupResult(id=None, results=None, parent=None, **kwargs)[source]

Like ResultSet, but with an associated id.

This type is returned by group.

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

Parameters:

as_tuple()[source]

property 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, app=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)

class celery.result.ResultBase[source]

Base class for results.

parent = None

Parent result (if part of a chain)

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

A collection of results.

Parameters:

results (Sequence _[_AsyncResult]) – 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.

property app

property backend

clear()[source]

Remove all results from this set.

completed_count()[source]

Task completion count.

Note that complete means successful in this context. In other words, the return value of this method is the number of successful tasks.

Returns:

the number of complete (i.e. successful) tasks.

Return type:

int

discard(result)[source]

Remove result from the set if it is a member.

Does nothing if it’s not a member.

failed()[source]

Return true if any of the tasks failed.

Returns:

true if one of the tasks failed.

(i.e., raised an exception)

Return type:

bool

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, on_message=None, disable_sync_subtasks=True, on_interval=None)[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, on_message=None, on_interval=None)[source]

Backend optimized version of iterate().

Added 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.

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

Gather 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.

Parameters:

Raises:

celery.exceptions.TimeoutError – if timeout isn’tNone and the operation takes longer than timeout seconds.

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

Backend optimized version of join().

Added 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(callback=None, propagate=True)

maybe_throw(callback=None, propagate=True)[source]

ready()[source]

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

Returns:

true if all of the tasks have been executed.

Return type:

bool

remove(result)[source]

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

Raises:

KeyError – if the result isn’t 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:

successful()[source]

Return true if all tasks successful.

Returns:

true if all of the tasks finished

successfully (i.e. didn’t raise an exception).

Return type:

bool

property supports_native_join

then(callback, on_error=None, weak=False)[source]

update(results)[source]

Extend from iterable of results.

waiting()[source]

Return true if any of the tasks are incomplete.

Returns:

true if one of the tasks are still

waiting for execution.

Return type:

bool

celery.result.result_from_tuple(r, app=None)[source]

Deserialize result from tuple.