celery.result

Task results/state and results for groups of tasks.

class celery.result.AsyncResult(id, backend=None, task_name=None, app=None, parent=None)[исходный код]

Query task state.

Параметры:
exception TimeoutError

The operation timed out.

app = None
property args
as_list()[исходный код]

Return as a list of task IDs.

as_tuple()[исходный код]
backend = None

The task result backend to use.

build_graph(intermediate=False, formatter=None)[исходный код]
property children
collect(intermediate=False, **kwargs)[исходный код]

Collect results as they return.

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

Примечание

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()[исходный код]

Return True if the task failed.

forget()[исходный код]

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'}))[исходный код]

Wait until task is ready, and return its result.

Предупреждение

Waiting for tasks within a task may lead to deadlocks. Please read Избегайте запуска синхронных подзадач.

Предупреждение

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

Параметры:
  • timeout (float) – How long to wait, in seconds, before the operation times out.

  • propagate (bool) – Re-raise exception if the task failed.

  • interval (float) – Time to wait (in seconds) before retrying to retrieve the result. Note that this does not have any effect when using the RPC/redis result store backends, as they don’t use polling.

  • no_ack (bool) – Enable amqp no ack (automatically acknowledge message). If this is False then the message will not be acked.

  • follow_parents (bool) – Re-raise any exception raised by parent tasks.

  • disable_sync_subtasks (bool) – Disable tasks to wait for sub tasks this is the default configuration. CAUTION do not enable this unless you must.

Исключение:
  • celery.exceptions.TimeoutError – if timeout isn’t None and the result does not arrive within timeout seconds.

  • Exception – If the remote call raised an exception then that exception will be re-raised in the caller process.

get_leaf()[исходный код]
property graph
id = None

The task’s UUID.

property ignored

If True, task result retrieval is disabled.

property info

Task return value.

Примечание

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)[исходный код]
property kwargs
maybe_reraise(propagate=True, callback=None)
maybe_throw(propagate=True, callback=None)[исходный код]
property name
property queue
ready()[исходный код]

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.

Примечание

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)[исходный код]

Send revoke signal to all workers.

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

Параметры:
  • terminate (bool) – Also terminate the process currently working on the task (if any).

  • signal (str) – Name of signal to send to process if terminate. Default is TERM.

  • wait (bool) – Wait for replies from workers. The timeout argument specifies the seconds to wait. Disabled by default.

  • timeout (float) – Time in seconds to wait for replies when wait is enabled.

revoke_by_stamped_headers(headers, connection=None, terminate=False, signal=None, wait=False, timeout=None)[исходный код]

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.

Параметры:
  • headers (dict[str, Union(str, list)]) – Headers to match when revoking tasks.

  • terminate (bool) – Also terminate the process currently working on the task (if any).

  • signal (str) – Name of signal to send to process if terminate. Default is TERM.

  • wait (bool) – Wait for replies from workers. The timeout argument specifies the seconds to wait. Disabled by default.

  • timeout (float) – Time in seconds to wait for replies when wait is enabled.

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()[исходный код]

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)[исходный код]
throw(*args, **kwargs)[исходный код]
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.

Предупреждение

Waiting for tasks within a task may lead to deadlocks. Please read Избегайте запуска синхронных подзадач.

Предупреждение

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

Параметры:
  • timeout (float) – How long to wait, in seconds, before the operation times out.

  • propagate (bool) – Re-raise exception if the task failed.

  • interval (float) – Time to wait (in seconds) before retrying to retrieve the result. Note that this does not have any effect when using the RPC/redis result store backends, as they don’t use polling.

  • no_ack (bool) – Enable amqp no ack (automatically acknowledge message). If this is False then the message will not be acked.

  • follow_parents (bool) – Re-raise any exception raised by parent tasks.

  • disable_sync_subtasks (bool) – Disable tasks to wait for sub tasks this is the default configuration. CAUTION do not enable this unless you must.

Исключение:
  • celery.exceptions.TimeoutError – if timeout isn’t None and the result does not arrive within timeout seconds.

  • Exception – If the remote call raised an exception then that exception will be re-raised in the caller process.

property worker
class celery.result.EagerResult(id, ret_value, state, traceback=None)[исходный код]

Result that we know has already been executed.

forget()[исходный код]

Forget the result of this task and its parents.

get(timeout=None, propagate=True, disable_sync_subtasks=True, **kwargs)[исходный код]

Wait until task is ready, and return its result.

Предупреждение

Waiting for tasks within a task may lead to deadlocks. Please read Избегайте запуска синхронных подзадач.

Предупреждение

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

Параметры:
  • timeout (float) – How long to wait, in seconds, before the operation times out.

  • propagate (bool) – Re-raise exception if the task failed.

  • interval (float) – Time to wait (in seconds) before retrying to retrieve the result. Note that this does not have any effect when using the RPC/redis result store backends, as they don’t use polling.

  • no_ack (bool) – Enable amqp no ack (automatically acknowledge message). If this is False then the message will not be acked.

  • follow_parents (bool) – Re-raise any exception raised by parent tasks.

  • disable_sync_subtasks (bool) – Disable tasks to wait for sub tasks this is the default configuration. CAUTION do not enable this unless you must.

Исключение:
  • celery.exceptions.TimeoutError – if timeout isn’t None and the result does not arrive within timeout seconds.

  • Exception – If the remote call raised an exception then that exception will be re-raised in the caller process.

ready()[исходный код]

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)[исходный код]

Send revoke signal to all workers.

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

Параметры:
  • terminate (bool) – Also terminate the process currently working on the task (if any).

  • signal (str) – Name of signal to send to process if terminate. Default is TERM.

  • wait (bool) – Wait for replies from workers. The timeout argument specifies the seconds to wait. Disabled by default.

  • timeout (float) – Time in seconds to wait for replies when wait is enabled.

property state

The tasks state.

property status

The tasks state.

property supports_native_join
then(callback, on_error=None, weak=False)[исходный код]
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.

Предупреждение

Waiting for tasks within a task may lead to deadlocks. Please read Избегайте запуска синхронных подзадач.

Предупреждение

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

Параметры:
  • timeout (float) – How long to wait, in seconds, before the operation times out.

  • propagate (bool) – Re-raise exception if the task failed.

  • interval (float) – Time to wait (in seconds) before retrying to retrieve the result. Note that this does not have any effect when using the RPC/redis result store backends, as they don’t use polling.

  • no_ack (bool) – Enable amqp no ack (automatically acknowledge message). If this is False then the message will not be acked.

  • follow_parents (bool) – Re-raise any exception raised by parent tasks.

  • disable_sync_subtasks (bool) – Disable tasks to wait for sub tasks this is the default configuration. CAUTION do not enable this unless you must.

Исключение:
  • celery.exceptions.TimeoutError – if timeout isn’t None and the result does not arrive within timeout seconds.

  • Exception – If the remote call raised an exception then that exception will be re-raised in the caller process.

class celery.result.GroupResult(id=None, results=None, parent=None, **kwargs)[исходный код]

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.

Параметры:
  • id (str) – The id of the group.

  • results (Sequence[AsyncResult]) – List of result instances.

  • parent (ResultBase) – Parent result of this group.

as_tuple()[исходный код]
property children
delete(backend=None)[исходный код]

Remove this result if it was previously saved.

id = None

The UUID of the group.

classmethod restore(id, backend=None, app=None)[исходный код]

Restore previously saved group result.

results = None

List/iterator of results in the group

save(backend=None)[исходный код]

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

Пример

>>> def save_and_restore(result):
...     result.save()
...     result = GroupResult.restore(result.id)
class celery.result.ResultBase[исходный код]

Base class for results.

parent = None

Parent result (if part of a chain)

class celery.result.ResultSet(results, app=None, ready_barrier=None, **kwargs)[исходный код]

A collection of results.

Параметры:

results (Sequence[AsyncResult]) – List of result instances.

add(result)[исходный код]

Add AsyncResult as a new member of the set.

Does nothing if the result is already a member.

property app
property backend
clear()[исходный код]

Remove all results from this set.

completed_count()[исходный код]

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.

Результат:

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

Тип результата:

int

discard(result)[исходный код]

Remove result from the set if it is a member.

Does nothing if it’s not a member.

failed()[исходный код]

Return true if any of the tasks failed.

Результат:

true if one of the tasks failed.

(i.e., raised an exception)

Тип результата:

bool

forget()[исходный код]

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)[исходный код]

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)[исходный код]

Backend optimized version of iterate().

Добавлено в версии 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)[исходный код]

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

Примечание

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.

Предупреждение

Waiting for tasks within a task may lead to deadlocks. Please see Избегайте запуска синхронных подзадач.

Параметры:
  • timeout (float) – The number of seconds to wait for results before the operation times out.

  • propagate (bool) – If any of the tasks raises an exception, the exception will be re-raised when this flag is set.

  • interval (float) – 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 (Callable) – 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’ll 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 (bool) – Automatic message acknowledgment (Note that if this is set to False then the messages will not be acknowledged).

  • disable_sync_subtasks (bool) – Disable tasks to wait for sub tasks this is the default configuration. CAUTION do not enable this unless you must.

Исключение:

celery.exceptions.TimeoutError – if timeout isn’t None 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)[исходный код]

Backend optimized version of join().

Добавлено в версии 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)[исходный код]
ready()[исходный код]

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

Результат:

true if all of the tasks have been executed.

Тип результата:

bool

remove(result)[исходный код]

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

Исключение:

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)[исходный код]

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

Параметры:
  • terminate (bool) – Also terminate the process currently working on the task (if any).

  • signal (str) – Name of signal to send to process if terminate. Default is TERM.

  • wait (bool) – Wait for replies from worker. The timeout argument specifies the number of seconds to wait. Disabled by default.

  • timeout (float) – Time in seconds to wait for replies when the wait argument is enabled.

successful()[исходный код]

Return true if all tasks successful.

Результат:

true if all of the tasks finished

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

Тип результата:

bool

property supports_native_join
then(callback, on_error=None, weak=False)[исходный код]
update(results)[исходный код]

Extend from iterable of results.

waiting()[исходный код]

Return true if any of the tasks are incomplete.

Результат:

true if one of the tasks are still

waiting for execution.

Тип результата:

bool

celery.result.result_from_tuple(r, app=None)[исходный код]

Deserialize result from tuple.

Back to Top