fastapi-master/docs_src/events/tutorial002.py

15 lines
255 B
Python
Raw Permalink Normal View History

2024-08-24 12:41:47 +08:00
from fastapi import FastAPI
app = FastAPI()
@app.on_event("shutdown")
def shutdown_event():
with open("log.txt", mode="a") as log:
log.write("Application shutdown")
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]