Skip to main content

chunks

Partition of tasks into chunks of size n.

Constructor

Signature

def chunks(
task: Any,
it: Iterable,
n: int,
**options: dict
) - > null

Parameters

NameTypeDescription
taskAnyThe task to be executed in chunks.
itIterableThe iterable containing the data to be partitioned.
nintThe size of each chunk.
**optionsdictAdditional execution and message options.

Signature

def chunks(
task: string|Signature,
it: iterable,
n: int
)

Parameters

NameTypeDescription
task`stringSignature`
ititerableThe iterable of arguments to be partitioned into chunks
nintThe number of items to include in each chunk

Methods


from_dict()

@classmethod
def from_dict(
d: dict,
app: [Celery](../app/base/celery.md?sid=celery_app_base_celery)
) - > [chunks](chunks.md?sid=celery_canvas_chunks)

Creates a chunks instance from a dictionary representation containing task arguments and options.

Parameters

NameTypeDescription
ddictThe dictionary containing 'kwargs' (task, it, n) and 'options' for the signature
app[Celery](../app/base/celery.md?sid=celery_app_base_celery)The Celery application instance to associate with this signature

Returns

TypeDescription
[chunks](chunks.md?sid=celery_canvas_chunks)A new chunks signature instance initialized with the provided dictionary data

apply_async()

@classmethod
def apply_async(
args: tuple,
kwargs: dict,
**opts: dict
) - > [AsyncResult](../result/asyncresult.md?sid=celery_result_asyncresult)

Dispatches the chunked tasks to the broker for asynchronous execution.

Parameters

NameTypeDescription
argstupleAdditional positional arguments for the task execution
kwargsdictAdditional keyword arguments for the task execution
**optsdictRouting and execution options for the Celery broker

Returns

TypeDescription
[AsyncResult](../result/asyncresult.md?sid=celery_result_asyncresult)A result object that tracks the execution of the underlying task group

group()

@classmethod
def group() - > [group](group.md?sid=celery_canvas_group)

Converts the chunks instance into a group of starmap signatures.

Returns

TypeDescription
[group](group.md?sid=celery_canvas_group)A Celery group containing individual task signatures for each data partition

apply_chunks()

@classmethod
def apply_chunks(
task: string|Signature,
it: iterable,
n: int,
app: [Celery](../app/base/celery.md?sid=celery_app_base_celery)
) - > [AsyncResult](../result/asyncresult.md?sid=celery_result_asyncresult)

Creates a chunks instance and executes it immediately.

Parameters

NameTypeDescription
task`stringSignature`
ititerableThe data to be partitioned
nintThe size of each partition
app[Celery](../app/base/celery.md?sid=celery_app_base_celery)The Celery application instance to use for execution

Returns

TypeDescription
[AsyncResult](../result/asyncresult.md?sid=celery_result_asyncresult)The result of the executed chunked task group