Complete the code to import the asynccontextmanager decorator used for lifespan from contextlib.
from contextlib import [1]
The asynccontextmanager decorator is imported from contextlib to define a lifespan context manager.
Complete the code to define an async lifespan context manager function named 'lifespan'.
@asynccontextmanager async def [1](): print('Starting app') yield print('Shutting down app')
The async function decorated with @asynccontextmanager should be named lifespan by convention for the lifespan context manager.
Fix the error in the code to create a FastAPI app using the lifespan context manager.
app = FastAPI(lifespan=[1])The lifespan argument expects the function itself, not a call to it.
Fill both blanks to correctly use the lifespan context manager with async code.
from contextlib import [1] @[2] async def lifespan(): print('App starting') yield print('App shutting down')
Use asynccontextmanager from contextlib and decorate the function with @asynccontextmanager to define an async lifespan context manager.
Fill all three blanks to create a FastAPI app with a lifespan context manager that prints messages on startup and shutdown.
from contextlib import [1] from fastapi import FastAPI @[2] async def lifespan(): print('Starting') yield print('Stopping') app = FastAPI([3]=lifespan)
Import asynccontextmanager from contextlib, decorate the async function lifespan with @asynccontextmanager, and pass it as the lifespan argument to FastAPI.