Skip to content

Commit

Permalink
02-online serving/examples를 최신화 (#168)
Browse files Browse the repository at this point in the history
* refactor: pyproject.toml의 파이썬과 라이브러리 버전을 업데이트

* chore: 사용하지 않는 파일 삭제

* refactor: 11_event_handler.py 예제를 최신 fastapi 스타일로 변경

* chore: log.txt 추가
  • Loading branch information
heumsi authored Jan 16, 2024
1 parent 47b4019 commit 3094f38
Show file tree
Hide file tree
Showing 3 changed files with 503 additions and 618 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
from contextlib import asynccontextmanager

from fastapi import FastAPI
import uvicorn

app = FastAPI()

items = {}


@app.on_event("startup")
def startup_event():
@asynccontextmanager
async def lifespan(app: FastAPI):
print("Start Up Event")
items["foo"] = {"name": "Fighters"}
items["bar"] = {"name": "Tenders"}

yield

@app.on_event("shutdown")
def shutdown_event():
print("Shutdown Event!")
with open("log.txt", mode="a") as log:
log.write("Application shutdown")


app = FastAPI(lifespan=lifespan)


@app.get("/items/{item_id}")
def read_items(item_id: str):
return items[item_id]


if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=8000)


Loading

0 comments on commit 3094f38

Please sign in to comment.