Gunicorn keeps booting workers when onstartup raises exception #6309
-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI
app = FastAPI()
items = {}
@app.on_event("startup")
async def startup_event():
items["foo"] = {"name": "Fighters"}
items["bar"] = {"name": "Tenders"}
raise Exception
@app.get("/items/{item_id}")
async def read_items(item_id: str):
return items[item_id]
"""
gunicorn app:app --workers 1 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:80
"""DescriptionI am using the example straight from here starting the server locally using server-workers I have checked the following issues/threads for solutions, but somehow don't see any, perhaps I am missing on something obvious:
Ideally, I'd like to use the onstartup event to check all my DBs are reachable. And fail to start-up the app if not. But this just keepings on spinning up workers, never actually failing. Operating SystemLinux Operating System DetailsPRETTY_NAME="Debian GNU/Linux 11 (bullseye)" FastAPI Version0.68.2 Python VersionPython 3.10.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
Could you update to the most recent version of FastAPI? |
Beta Was this translation helpful? Give feedback.
-
|
Also latest version of Uvicorn! |
Beta Was this translation helpful? Give feedback.
-
|
Thank you guys, you're correct, updated versions of the 3 libs:
resulted in the following output: Now I just need to convince my organization to use the latest FastAPI and the other modules. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the help here @JarroVGIT and @iudeen ! 👏 🙇 Thanks for reporting back and closing the issue @alexanderluiscampino 👍 |
Beta Was this translation helpful? Give feedback.
Thank you guys, you're correct, updated versions of the 3 libs:
resulted in the following output: