19 changed files with 142 additions and 50 deletions
@ -1,14 +1,18 @@ |
|||
from fastapi import FastAPI |
|||
from contextlib import asynccontextmanager |
|||
|
|||
app = FastAPI() |
|||
from fastapi import FastAPI |
|||
|
|||
|
|||
@app.on_event("shutdown") |
|||
def shutdown_event(): |
|||
@asynccontextmanager |
|||
async def lifespan(app): |
|||
yield |
|||
with open("log.txt", mode="a") as log: |
|||
log.write("Application shutdown") |
|||
|
|||
|
|||
app = FastAPI(lifespan=lifespan) |
|||
|
|||
|
|||
@app.get("/items/") |
|||
async def read_items(): |
|||
return [{"name": "Foo"}] |
|||
|
|||
Loading…
Reference in new issue