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)