Do some stuff on SIGTERM *before* the app shuts down #11756
Unanswered
Jakobhenningjensen
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
My FastAPI is run (uvicorn) in a Kubernetes cluster.
I'm trying to gracefully shut it down when the cluster is scaling down.
What I want to do is when I get a sigterm
losely speaking - I want to run a function when
SIGTERM
is received without "messing" with the sigterm-handlerStep (1) can be done by creating a function and pass it to
signal.signal(signal.SIGTERM, ...)
but that is being called after the "shutdown" event in the lifespan. I have thought about setting it in thelifespan
event, but as far as I understand that happens after the app is shut down - I want to do it before the app shuts down .Operating System
Linux
Operating System Details
No response
FastAPI Version
0.111.0
Pydantic Version
2.7.4
Python Version
3.11.8
Additional Context
Beta Was this translation helpful? Give feedback.
All reactions