new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

FastAPI · Reference · all subjects

background_tasks

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

BackgroundTasks import location

BackgroundTasks can be imported directly from the fastapi module using 'from fastapi import BackgroundTasks'.

BackgroundTasks parameter declaration

You can declare a parameter with the type BackgroundTasks in a path operation function or dependency function to schedule the execution of background tasks after the response is sent.

How to implement background tasks in FastAPI

To implement background tasks in FastAPI, declare a parameter of type BackgroundTasks in your path operation function or dependency function, then use it to schedule tasks that will execute after the response is sent to the client.

Background tasks should manage their own resources

Background tasks should be independent logic blocks handled separately with their own resources, such as their own database connection. Instead of sharing a database session from a yield dependency, create a new database session within the background task itself. Pass only data (like object IDs) to the background task function, not objects that depend on yield dependency resources.

Give your agent this brain