Skip to main content

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

AttributeTypeDescription
tasksList[[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

NameTypeDescription
*tasksList[[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.
**optionsAnyExecution 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

NameTypeDescription
ddictThe dictionary containing the group definition, including tasks in d['kwargs']['tasks']
app[Celery](../app/base/celery.md?sid=celery_app_base_celery) = NoneThe Celery application instance to associate with the new group

Returns

TypeDescription
[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

NameTypeDescription
startfloat = 1.0The initial countdown delay for the first task in the group
stopfloat = NoneThe maximum countdown delay allowed
stepfloat = 1.0The increment added to the countdown for each subsequent task

Returns

TypeDescription
[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

NameTypeDescription
argstuple = NonePositional arguments to pass to each task in the group
kwargsdict = NoneKeyword arguments to pass to each task in the group
add_to_parentbool = TrueWhether to attach the group result to the current task's trail for tracking
producerProducer = NoneThe custom producer to use for publishing task messages
link[Signature](signature.md?sid=celery_canvas_signature) = NoneUnsupported for groups; raises TypeError if provided
link_error[Signature](signature.md?sid=celery_canvas_signature) = NoneUnsupported for groups; raises TypeError if provided

Returns

TypeDescription
[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

NameTypeDescription
argstuple = NonePositional arguments for the tasks
kwargsdict = NoneKeyword arguments for the tasks

Returns

TypeDescription
[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

NameTypeDescription
immutableboolThe boolean value to apply to each task's immutable property

Returns

TypeDescription
nullnull

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

NameTypeDescription
visitor[StampingVisitor](stampingvisitor.md?sid=celery_canvas_stampingvisitor) = NoneAn object that defines hooks for group start and end events
append_stampsbool = FalseWhether to append new stamps to existing ones instead of overwriting
**headersAnyThe metadata headers to be applied to the tasks

Returns

TypeDescription
nullnull

@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

NameTypeDescription
sig[Signature](signature.md?sid=celery_canvas_signature)The callback task to execute after the first task in the group finishes

Returns

TypeDescription
[Signature](signature.md?sid=celery_canvas_signature)The linked signature attached to the first task

@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

NameTypeDescription
sig[Signature](signature.md?sid=celery_canvas_signature)The error handler task to execute if any task in the group fails

Returns

TypeDescription
tupleA 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

NameTypeDescription
group_idstr = NoneThe group ID to use; if None, a new UUID is generated

Returns

TypeDescription
[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

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