Skip to main content

ResultSet

A collection of results.

Attributes

AttributeTypeDescription
resultsSequence[[AsyncResult](asyncresult.md?sid=celery_result_asyncresult)] = NoneList of results in in the set.
maybe_reraisecallable = maybe_throwAn alias for the maybe_throw method used for backward compatibility to re-raise exceptions from failed tasks.

Constructor

Signature

def ResultSet(
results: Sequence[[AsyncResult](asyncresult.md?sid=celery_result_asyncresult)],
app: [Celery](../app/base/celery.md?sid=celery_app_base_celery) = None,
ready_barrier: barrier = None,
kwargs: dict
) - > null

Parameters

NameTypeDescription
resultsSequence[[AsyncResult](asyncresult.md?sid=celery_result_asyncresult)]A list or sequence of result instances to be included in the set.
app[Celery](../app/base/celery.md?sid=celery_app_base_celery) = NoneThe Celery application instance associated with these results.
ready_barrierbarrier = NoneAn optional barrier used to track when all results in the set are ready.
kwargsdictAdditional keyword arguments.

Methods


add()

@classmethod
def add(
result: [AsyncResult](asyncresult.md?sid=celery_result_asyncresult)
) - > null

Add :class:AsyncResult as a new member of the set. Does nothing if the result is already a member.

Parameters

NameTypeDescription
result[AsyncResult](asyncresult.md?sid=celery_result_asyncresult)The asynchronous result instance to include in this collection.

Returns

TypeDescription
null

remove()

@classmethod
def remove(
result: AsyncResult | str
) - > null

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

Parameters

NameTypeDescription
result`AsyncResultstr`

Returns

TypeDescription
null

discard()

@classmethod
def discard(
result: AsyncResult | str
) - > null

Remove result from the set if it is a member. Does nothing if it's not a member.

Parameters

NameTypeDescription
result`AsyncResultstr`

Returns

TypeDescription
null

update()

@classmethod
def update(
results: Iterable[[AsyncResult](asyncresult.md?sid=celery_result_asyncresult)]
) - > null

Extend from iterable of results.

Parameters

NameTypeDescription
resultsIterable[[AsyncResult](asyncresult.md?sid=celery_result_asyncresult)]A collection of result instances to merge into the current set.

Returns

TypeDescription
null

clear()

@classmethod
def clear() - > null

Remove all results from this set.

Returns

TypeDescription
null

successful()

@classmethod
def successful() - > bool

Return true if all tasks successful.

Returns

TypeDescription
booltrue if all of the tasks finished successfully (i.e. didn't raise an exception).

failed()

@classmethod
def failed() - > bool

Return true if any of the tasks failed.

Returns

TypeDescription
booltrue if one of the tasks failed. (i.e., raised an exception)

maybe_throw()

@classmethod
def maybe_throw(
callback: Callable,
propagate: bool
) - > null

Iterates through all results and re-raises the first exception encountered if the task failed.

Parameters

NameTypeDescription
callbackCallableOptional function to apply to each result during iteration.
propagateboolWhether to re-raise exceptions found in the results.

Returns

TypeDescription
null

waiting()

@classmethod
def waiting() - > bool

Return true if any of the tasks are incomplete.

Returns

TypeDescription
booltrue if one of the tasks are still waiting for execution.

ready()

@classmethod
def ready() - > bool

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

Returns

TypeDescription
booltrue if all of the tasks have been executed.

completed_count()

@classmethod
def completed_count() - > int

Task completion count. Note that complete means successful in this context.

Returns

TypeDescription
intthe number of complete (i.e. successful) tasks.

forget()

@classmethod
def forget() - > null

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

Returns

TypeDescription
null

revoke()

@classmethod
def revoke(
connection: [Connection](../worker/consumer/connection/connection.md?sid=celery_worker_consumer_connection_connection),
terminate: bool,
signal: str,
wait: bool,
timeout: float
) - > null

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

Parameters

NameTypeDescription
connection[Connection](../worker/consumer/connection/connection.md?sid=celery_worker_consumer_connection_connection)Optional broker connection to use for sending the revoke signal.
terminateboolAlso terminate the process currently working on the task (if any).
signalstrName of signal to send to process if terminate. Default is TERM.
waitboolWait for replies from worker.
timeoutfloatTime in seconds to wait for replies when the wait argument is enabled.

Returns

TypeDescription
null

get()

@classmethod
def get(
timeout: float,
propagate: bool,
interval: float,
callback: Callable,
no_ack: bool,
on_message: Callable,
disable_sync_subtasks: bool,
on_interval: Callable
) - > list

See :meth:join. This is here for API compatibility with :class:AsyncResult, in addition it uses :meth:join_native if available for the current result backend.

Parameters

NameTypeDescription
timeoutfloatThe number of seconds to wait for results before timing out.
propagateboolWhether to re-raise exceptions from failed tasks.
intervalfloatPolling interval for backends that do not support native events.
callbackCallableOptional function called for every result received.
no_ackboolWhether to disable automatic message acknowledgment.
on_messageCallableCallback for when a message is received (backend dependent).
disable_sync_subtasksboolPrevents tasks from waiting for subtasks to avoid deadlocks.
on_intervalCallableCallback called on every polling interval.

Returns

TypeDescription
listA list of task return values in the same order as the results in this set.

join()

@classmethod
def join(
timeout: float,
propagate: bool,
interval: float,
callback: Callable,
no_ack: bool,
on_message: Callable,
disable_sync_subtasks: bool,
on_interval: Callable
) - > list

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

Parameters

NameTypeDescription
timeoutfloatThe number of seconds to wait for results before the operation times out.
propagateboolIf any of the tasks raises an exception, the exception will be re-raised when this flag is set.
intervalfloatTime to wait (in seconds) before retrying to retrieve a result from the set.
callbackCallableOptional callback to be called for every result received.
no_ackboolAutomatic message acknowledgment.
on_messageCallableCallback for when a message is received.
disable_sync_subtasksboolDisable tasks to wait for sub tasks.
on_intervalCallableCallback called on every polling interval.

Returns

TypeDescription
listA list of task return values in the same order as the results in this set.

then()

@classmethod
def then(
callback: Callable,
on_error: Callable,
weak: bool
) - > promise

Adds a callback to be executed when all results in the set are ready.

Parameters

NameTypeDescription
callbackCallableThe function to call when the results are ready.
on_errorCallableThe function to call if an error occurs.
weakboolWhether to use a weak reference for the callback.

Returns

TypeDescription
promiseA promise object that resolves when the set is ready.

iter_native()

@classmethod
def iter_native(
timeout: float,
interval: float,
no_ack: bool,
on_message: Callable,
on_interval: Callable
) - > Iterator

Backend optimized version of :meth:iterate.

Parameters

NameTypeDescription
timeoutfloatThe number of seconds to wait before timing out.
intervalfloatPolling interval for backends that require it.
no_ackboolWhether to disable message acknowledgment.
on_messageCallableCallback for when a message is received.
on_intervalCallableCallback called on every polling interval.

Returns

TypeDescription
IteratorAn iterator yielding (task_id, result) pairs using native backend features.

join_native()

@classmethod
def join_native(
timeout: float,
propagate: bool,
interval: float,
callback: Callable,
no_ack: bool,
on_message: Callable,
on_interval: Callable,
disable_sync_subtasks: bool
) - > list

Backend optimized version of :meth:join.

Parameters

NameTypeDescription
timeoutfloatThe number of seconds to wait before timing out.
propagateboolWhether to re-raise exceptions from failed tasks.
intervalfloatPolling interval for backends that require it.
callbackCallableOptional function called for every result received.
no_ackboolWhether to disable message acknowledgment.
on_messageCallableCallback for when a message is received.
on_intervalCallableCallback called on every polling interval.
disable_sync_subtasksboolPrevents tasks from waiting for subtasks.

Returns

TypeDescription
listA list of task return values in the same order as the results in this set.

supports_native_join()

@classmethod
def supports_native_join() - > bool

Checks if the underlying backend supports optimized native join operations.

Returns

TypeDescription
boolTrue if the backend supports native join, False otherwise.

app()

@classmethod
def app() - > [Celery](../app/base/celery.md?sid=celery_app_base_celery)

Retrieves the Celery application instance associated with this result set.

Returns

TypeDescription
[Celery](../app/base/celery.md?sid=celery_app_base_celery)The Celery app instance.

backend()

@classmethod
def backend() - > [Backend](../backends/base/backend.md?sid=celery_backends_base_backend)

Retrieves the result backend instance used to fetch task states.

Returns

TypeDescription
[Backend](../backends/base/backend.md?sid=celery_backends_base_backend)The result backend instance.