Skip to content

Commit 589c88f

Browse files
author
Chiara Rasi
committed
Replaced deprecated app on event with app lifespan
1 parent 798a288 commit 589c88f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Removed the example of an old json submission (before 2022-11-21)
99
- Updated actions using the latest base images and to run using Python 3.9
1010
- Docker image uses Python 3.11 instead of 3.8
11+
- Replaced deprecated app "on event" with app lifespan
1112
### Fixed
1213
- Updated issue templates
1314
- Updated a number of libraries to address all current security advisories

preClinVar/main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
import re
4+
from contextlib import asynccontextmanager
45
from typing import List
56

67
import requests
@@ -16,16 +17,18 @@
1617

1718
LOG = logging.getLogger("uvicorn.access")
1819

19-
app = FastAPI()
2020

21-
22-
@app.on_event("startup")
23-
async def startup_event():
21+
@asynccontextmanager
22+
async def lifespan(app_: FastAPI):
2423
LOG = logging.getLogger("uvicorn.access")
2524
console_formatter = uvicorn.logging.ColourizedFormatter(
2625
"{levelprefix} {asctime} : {message}", style="{", use_colors=True
2726
)
2827
LOG.handlers[0].setFormatter(console_formatter)
28+
yield # This is crucial for the lifespan context manager
29+
30+
31+
app = FastAPI(lifespan=lifespan)
2932

3033

3134
@app.get("/")

0 commit comments

Comments
 (0)