benoitc / gunicorn

gunicorn 'Green Unicorn' is a WSGI HTTP Server for UNIX, fast clients and sleepy applications.
http://www.gunicorn.org
Other
9.88k stars 1.76k forks source link

ctrl+c #3231

Closed yyqiekenao closed 3 months ago

yyqiekenao commented 5 months ago

When I use Ctrl+C to stop my service, it also terminates the Python interpreter. This causes issues with proper cleanup and resource management, especially with Redis connection pools and other resources that require graceful shutdown. I'm running my FastAPI application with Gunicorn using the following command:

gunicorn app:app -c gunicorn.conf.py --enable-stdio-inheritance --reload

gunicorn.conf.py

from application.logger import LOGGING

bind = "127.0.0.1" workers = 4 worker_class = "uvicorn.workers.UvicornWorker" loglevel = "info" log_config = LOGGING

benoitc commented 3 months ago

you can attach redis cleanum to the https://docs.python.org/3/library/atexit.html or handle cleanup using one of the hook. In theory that shouldn't be an issue.