BackgroundTasks
A collection of background tasks that will be called after a response has been sent to the client.
Attributes
| Attribute | Type | Description |
|---|---|---|
| tasks | list[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
| Name | Type | Description |
|---|---|---|
| func | Callable | The function to call after the response is sent. It can be a regular def function or an async def function. |
| *args | Any | Positional arguments to be passed to the background function when it is executed. |
| **kwargs | Any | Keyword arguments to be passed to the background function when it is executed. |
Returns
| Type | Description |
|---|---|
None | Nothing is returned; the task is registered for execution after the response cycle. |