Skip to main content

BackgroundTasks

A collection of background tasks that will be called after a response has been sent to the client.

Attributes

AttributeTypeDescription
taskslist[BackgroundTask] = []A list of background task objects to be executed after the response is sent, inherited from Starlette.

Constructor

Signature

def BackgroundTasks() - > null

Methods


add_task()

@classmethod
def add_task(
func: Callable,
*args: Any,
**kwargs: Any
) - > None

Add a function to be called in the background after the response is sent.

Parameters

NameTypeDescription
funcCallableThe function to call after the response is sent. It can be a regular def function or an async def function.
*argsAnyPositional arguments to be passed to the background function when it is executed.
**kwargsAnyKeyword arguments to be passed to the background function when it is executed.

Returns

TypeDescription
NoneNothing is returned; the task is registered for execution after the response cycle.