Country or region and language

    Choose your country or region and your language.

    Suggested for you

      All countries and regions

        Choose your character

        It shows in the top bar and on your profile. Change it any time.

        Sign in or join
        Opening Python for software engineers
        Your turn

        FastAPI background tasks

        After the response, in order

        Declare tasks: BackgroundTasks on a handler and call tasks.add_task(audit, text). FastAPI builds the response first and then runs the tasks in the order you added them. A count the handler reads from the log is therefore the count before its own task runs, and the exercises check exactly that.

        When a task never runs

        Tasks belong to the response the handler returns. If the handler raises HTTPException after adding a task, FastAPI sends an error response without it, so the task is dropped. Use async def task functions here: FastAPI sends plain functions to a thread pool, and this browser runtime has none. The background tasks docs cover the same API. Work that must survive a crash belongs in a durable queue, which the unit’s interview tasks ask you to explain.

        Guides on this topic

        Your Work Gym account

        Save your progress and pick up on another device. Your browser's progress comes with you.

        Your account can start a 5-day free trial: every course, unit, project and exam. Card needed; cancel any time and pay nothing.

        New accounts get 6 hours of full access: every course, unit, project and exam. The clock starts when you go past the free lessons.

        Plan your practice from a job ad or syllabus

        Have a referral code?

        or

        You can keep practicing without an account.

        Change your plan

        Checking the price

        Help and feedback

        Ask a question, tell us what is not working, or share an idea. We reply by email.

        What is it about?

        We use it only to reply to you.