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") |
@asynccontextmanager |
||||
def shutdown_event(): |
async def lifespan(app): |
||||
|
yield |
||||
with open("log.txt", mode="a") as log: |
with open("log.txt", mode="a") as log: |
||||
log.write("Application shutdown") |
log.write("Application shutdown") |
||||
|
|
||||
|
|
||||
|
app = FastAPI(lifespan=lifespan) |
||||
|
|
||||
|
|
||||
@app.get("/items/") |
@app.get("/items/") |
||||
async def read_items(): |
async def read_items(): |
||||
return [{"name": "Foo"}] |
return [{"name": "Foo"}] |
||||
|
|||||
Loading…
Reference in new issue