background_tasks#

class litestar.background_tasks.BackgroundTask#

Bases: object

A container for a ‘background’ task function.

Background tasks are called once a Response finishes.

__init__(fn: ~typing.Callable[[~P], ~typing.Any], *args: ~typing.~P, **kwargs: ~typing.~P) None#

Initialize BackgroundTask.

Parameters:
  • fn – A sync or async function to call as the background task.

  • *args – Args to pass to the func.

  • **kwargs – Kwargs to pass to the func

async __call__() None#

Call the wrapped function with the passed in arguments.

Returns:

None

class litestar.background_tasks.BackgroundTasks#

Bases: object

A container for multiple ‘background’ task functions.

Background tasks are called once a Response finishes.

__init__(tasks: Iterable[BackgroundTask], run_in_task_group: bool = False) None#

Initialize BackgroundTasks.

Parameters:
  • tasks – An iterable of BackgroundTask instances.

  • run_in_task_group – If you set this value to True than the tasks will run concurrently, using a TaskGroup. Note: This will not preserve execution order.

async __call__() None#

Call the wrapped background tasks.

Returns:

None