A collection of results.
Attributes
| Attribute | Type | Description |
|---|
| results | Sequence[[AsyncResult](asyncresult.md?sid=celery_result_asyncresult)] = None | List of results in in the set. |
| maybe_reraise | callable = maybe_throw | An 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
| Name | Type | Description |
|---|
| results | Sequence[[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) = None | The Celery application instance associated with these results. |
| ready_barrier | barrier = None | An optional barrier used to track when all results in the set are ready. |
| kwargs | dict | Additional 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
| Name | Type | Description |
|---|
| result | [AsyncResult](asyncresult.md?sid=celery_result_asyncresult) | The asynchronous result instance to include in this collection. |
Returns
remove()
@classmethod
def remove(
result: AsyncResult | str
) - > null
Remove result from the set; it must be a member.
Parameters
| Name | Type | Description |
|---|
| result | `AsyncResult | str` |
Returns
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
| Name | Type | Description |
|---|
| result | `AsyncResult | str` |
Returns
update()
@classmethod
def update(
results: Iterable[[AsyncResult](asyncresult.md?sid=celery_result_asyncresult)]
) - > null
Extend from iterable of results.
Parameters
| Name | Type | Description |
|---|
| results | Iterable[[AsyncResult](asyncresult.md?sid=celery_result_asyncresult)] | A collection of result instances to merge into the current set. |
Returns
clear()
@classmethod
def clear() - > null
Remove all results from this set.
Returns
successful()
@classmethod
def successful() - > bool
Return true if all tasks successful.
Returns
| Type | Description |
|---|
bool | true 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
| Type | Description |
|---|
bool | true 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
| Name | Type | Description |
|---|
| callback | Callable | Optional function to apply to each result during iteration. |
| propagate | bool | Whether to re-raise exceptions found in the results. |
Returns
waiting()
@classmethod
def waiting() - > bool
Return true if any of the tasks are incomplete.
Returns
| Type | Description |
|---|
bool | true 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
| Type | Description |
|---|
bool | true 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
| Type | Description |
|---|
int | the number of complete (i.e. successful) tasks. |
forget()
@classmethod
def forget() - > null
Forget about (and possible remove the result of) all the tasks.
Returns
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
| Name | Type | Description |
|---|
| connection | [Connection](../worker/consumer/connection/connection.md?sid=celery_worker_consumer_connection_connection) | Optional broker connection to use for sending the revoke signal. |
| 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. |
| timeout | float | Time in seconds to wait for replies when the wait argument is enabled. |
Returns
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
| Name | Type | Description |
|---|
| timeout | float | The number of seconds to wait for results before timing out. |
| propagate | bool | Whether to re-raise exceptions from failed tasks. |
| interval | float | Polling interval for backends that do not support native events. |
| callback | Callable | Optional function called for every result received. |
| no_ack | bool | Whether to disable automatic message acknowledgment. |
| on_message | Callable | Callback for when a message is received (backend dependent). |
| disable_sync_subtasks | bool | Prevents tasks from waiting for subtasks to avoid deadlocks. |
| on_interval | Callable | Callback called on every polling interval. |
Returns
| Type | Description |
|---|
list | A 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
| Name | Type | Description |
|---|
| 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. |
| callback | Callable | Optional callback to be called for every result received. |
| no_ack | bool | Automatic message acknowledgment. |
| on_message | Callable | Callback for when a message is received. |
| disable_sync_subtasks | bool | Disable tasks to wait for sub tasks. |
| on_interval | Callable | Callback called on every polling interval. |
Returns
| Type | Description |
|---|
list | A 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
| Name | Type | Description |
|---|
| callback | Callable | The function to call when the results are ready. |
| on_error | Callable | The function to call if an error occurs. |
| weak | bool | Whether to use a weak reference for the callback. |
Returns
| Type | Description |
|---|
promise | A 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
| Name | Type | Description |
|---|
| timeout | float | The number of seconds to wait before timing out. |
| interval | float | Polling interval for backends that require it. |
| no_ack | bool | Whether to disable message acknowledgment. |
| on_message | Callable | Callback for when a message is received. |
| on_interval | Callable | Callback called on every polling interval. |
Returns
| Type | Description |
|---|
Iterator | An 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
| Name | Type | Description |
|---|
| timeout | float | The number of seconds to wait before timing out. |
| propagate | bool | Whether to re-raise exceptions from failed tasks. |
| interval | float | Polling interval for backends that require it. |
| callback | Callable | Optional function called for every result received. |
| no_ack | bool | Whether to disable message acknowledgment. |
| on_message | Callable | Callback for when a message is received. |
| on_interval | Callable | Callback called on every polling interval. |
| disable_sync_subtasks | bool | Prevents tasks from waiting for subtasks. |
Returns
| Type | Description |
|---|
list | A 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
| Type | Description |
|---|
bool | True 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
| Type | Description |
|---|
[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
| Type | Description |
|---|
[Backend](../backends/base/backend.md?sid=celery_backends_base_backend) | The result backend instance. |