From 4a46d39c93e67158a906bbce6291f6512f532ea8 Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 29 Oct 2025 14:06:03 +0800 Subject: [PATCH] Replace GUNICORN_CMD_ARGS with custom LIGHTRAG_GUNICORN_MODE flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Use custom env var for mode detection • Improve Gunicorn mode reliability --- lightrag/api/lightrag_server.py | 3 +-- lightrag/api/run_with_gunicorn.py | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lightrag/api/lightrag_server.py b/lightrag/api/lightrag_server.py index 47513b77..c4f4a3b1 100644 --- a/lightrag/api/lightrag_server.py +++ b/lightrag/api/lightrag_server.py @@ -328,8 +328,7 @@ def create_app(args): # In Gunicorn mode with preload_app=True, cleanup is handled by worker_exit/on_exit hooks # Only perform cleanup in Uvicorn single-process mode - if "GUNICORN_CMD_ARGS" not in os.environ: - + if "LIGHTRAG_GUNICORN_MODE" not in os.environ: # Clean up shared data finalize_share_data() diff --git a/lightrag/api/run_with_gunicorn.py b/lightrag/api/run_with_gunicorn.py index 5ad0c5b5..c5f7cb5c 100644 --- a/lightrag/api/run_with_gunicorn.py +++ b/lightrag/api/run_with_gunicorn.py @@ -34,6 +34,9 @@ def check_and_install_dependencies(): def main(): + # Set Gunicorn mode flag for lifespan cleanup detection + os.environ["LIGHTRAG_GUNICORN_MODE"] = "1" + # Check .env file if not check_env_file(): sys.exit(1)