group
Creates a group of tasks to be executed in parallel.
A group is lazy so you must call it to take action and evaluate the group.
Attributes
| Attribute | Type | Description |
|---|---|---|
| tasks | List[[Signature](signature.md?sid=celery_canvas_signature)] | Tasks in group. |
Constructor
Signature
def group(
*tasks: List[[Signature](signature.md?sid=celery_canvas_signature)],
**options: Any
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| *tasks | List[[Signature](signature.md?sid=celery_canvas_signature)] | A list of signatures to be executed. If a single iterable is provided, it is used as the task list. |
| **options | Any | Execution options applied to all tasks within the group. |
Methods
from_dict()
@classmethod
def from_dict(
d: dict,
app: [Celery](../app/base/celery.md?sid=celery_app_base_celery) = None
) - > [group](group.md?sid=celery_canvas_group)
Create a group signature from a dictionary that represents a group.
Parameters
| Name | Type | Description |
|---|---|---|
| d | dict | The dictionary containing the group definition, including tasks in d['kwargs']['tasks'] |
| app | [Celery](../app/base/celery.md?sid=celery_app_base_celery) = None | The Celery application instance to associate with the new group |
Returns
| Type | Description |
|---|---|
[group](group.md?sid=celery_canvas_group) | A new group signature instance populated with the tasks and options from the dictionary |
skew()
@classmethod
def skew(
start: float = 1.0,
stop: float = None,
step: float = 1.0
) - > [group](group.md?sid=celery_canvas_group)
Staggers the execution of tasks in the group by applying incremental countdown delays.
Parameters
| Name | Type | Description |
|---|---|---|
| start | float = 1.0 | The initial countdown delay for the first task in the group |
| stop | float = None | The maximum countdown delay allowed |
| step | float = 1.0 | The increment added to the countdown for each subsequent task |
Returns
| Type | Description |
|---|---|
[group](group.md?sid=celery_canvas_group) | The group instance with updated countdown options for its member tasks |
apply_async()
@classmethod
def apply_async(
args: tuple = None,
kwargs: dict = None,
add_to_parent: bool = True,
producer: Producer = None,
link: [Signature](signature.md?sid=celery_canvas_signature) = None,
link_error: [Signature](signature.md?sid=celery_canvas_signature) = None
) - > [GroupResult](../result/groupresult.md?sid=celery_result_groupresult)
Dispatches the group of tasks for asynchronous execution by the worker pool.
Parameters
| Name | Type | Description |
|---|---|---|
| args | tuple = None | Positional arguments to pass to each task in the group |
| kwargs | dict = None | Keyword arguments to pass to each task in the group |
| add_to_parent | bool = True | Whether to attach the group result to the current task's trail for tracking |
| producer | Producer = None | The custom producer to use for publishing task messages |
| link | [Signature](signature.md?sid=celery_canvas_signature) = None | Unsupported for groups; raises TypeError if provided |
| link_error | [Signature](signature.md?sid=celery_canvas_signature) = None | Unsupported for groups; raises TypeError if provided |
Returns
| Type | Description |
|---|---|
[GroupResult](../result/groupresult.md?sid=celery_result_groupresult) | A GroupResult instance containing the individual AsyncResult objects for each task |
apply()
@classmethod
def apply(
args: tuple = None,
kwargs: dict = None
) - > [GroupResult](../result/groupresult.md?sid=celery_result_groupresult)
Executes the group of tasks locally and synchronously in the current process.
Parameters
| Name | Type | Description |
|---|---|---|
| args | tuple = None | Positional arguments for the tasks |
| kwargs | dict = None | Keyword arguments for the tasks |
Returns
| Type | Description |
|---|---|
[GroupResult](../result/groupresult.md?sid=celery_result_groupresult) | A GroupResult containing the results of the tasks executed eagerly |
set_immutable()
@classmethod
def set_immutable(
immutable: bool
) - > null
Sets the immutable flag on all tasks within the group to prevent argument merging.
Parameters
| Name | Type | Description |
|---|---|---|
| immutable | bool | The boolean value to apply to each task's immutable property |
Returns
| Type | Description |
|---|---|
null | null |
stamp()
@classmethod
def stamp(
visitor: [StampingVisitor](stampingvisitor.md?sid=celery_canvas_stampingvisitor) = None,
append_stamps: bool = False,
**headers: Any
) - > null
Applies custom headers or metadata tags to all tasks in the group using a visitor pattern.
Parameters
| Name | Type | Description |
|---|---|---|
| visitor | [StampingVisitor](stampingvisitor.md?sid=celery_canvas_stampingvisitor) = None | An object that defines hooks for group start and end events |
| append_stamps | bool = False | Whether to append new stamps to existing ones instead of overwriting |
| **headers | Any | The metadata headers to be applied to the tasks |
Returns
| Type | Description |
|---|---|
null | null |
link()
@classmethod
def link(
sig: [Signature](signature.md?sid=celery_canvas_signature)
) - > [Signature](signature.md?sid=celery_canvas_signature)
Links a callback signature to the first task in the group.
Parameters
| Name | Type | Description |
|---|---|---|
| sig | [Signature](signature.md?sid=celery_canvas_signature) | The callback task to execute after the first task in the group finishes |
Returns
| Type | Description |
|---|---|
[Signature](signature.md?sid=celery_canvas_signature) | The linked signature attached to the first task |
link_error()
@classmethod
def link_error(
sig: [Signature](signature.md?sid=celery_canvas_signature)
) - > tuple
Links an error callback signature to every task in the group.
Parameters
| Name | Type | Description |
|---|---|---|
| sig | [Signature](signature.md?sid=celery_canvas_signature) | The error handler task to execute if any task in the group fails |
Returns
| Type | Description |
|---|---|
tuple | A tuple of the linked error signatures applied to each child task |
freeze()
@classmethod
def freeze(
group_id: str = None
) - > [GroupResult](../result/groupresult.md?sid=celery_result_groupresult)
Freezes the group, creating a GroupResult that represents the future results of the tasks.
Parameters
| Name | Type | Description |
|---|---|---|
| group_id | str = None | The group ID to use; if None, a new UUID is generated |
Returns
| Type | Description |
|---|---|
[GroupResult](../result/groupresult.md?sid=celery_result_groupresult) | A result object containing the frozen state and IDs of all tasks in the group |
app()
@classmethod
def app() - > [Celery](../app/base/celery.md?sid=celery_app_base_celery)
Retrieves the Celery application instance associated with this group or its tasks.
Returns
| Type | Description |
|---|---|
[Celery](../app/base/celery.md?sid=celery_app_base_celery) | The resolved Celery application instance |