Coverage for docs_src / background_tasks / tutorial001_py310.py: 100%
10 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi import BackgroundTasks, FastAPI 1abcd
3app = FastAPI() 1abcd
6def write_notification(email: str, message=""): 1abcd
7 with open("log.txt", mode="w") as email_file: 1efg
8 content = f"notification for {email}: {message}" 1efg
9 email_file.write(content) 1efg
12@app.post("/send-notification/{email}") 1abcd
13async def send_notification(email: str, background_tasks: BackgroundTasks): 1abcd
14 background_tasks.add_task(write_notification, email, message="some notification") 1efg
15 return {"message": "Notification sent in the background"} 1efg