diff --git a/lightrag/api/lightrag_server.py b/lightrag/api/lightrag_server.py index a9c9ab04..9f162290 100644 --- a/lightrag/api/lightrag_server.py +++ b/lightrag/api/lightrag_server.py @@ -470,8 +470,13 @@ def configure_logging(): def main(): - from multiprocessing import freeze_support + # Check if running under Gunicorn + if 'GUNICORN_CMD_ARGS' in os.environ: + # If started with Gunicorn, return directly as Gunicorn will call get_application + print("Running under Gunicorn - worker management handled by Gunicorn") + return + from multiprocessing import freeze_support freeze_support() args = parse_args() @@ -482,18 +487,7 @@ def main(): configure_logging() display_splash_screen(args) - - # Check if running under Gunicorn - if 'GUNICORN_CMD_ARGS' in os.environ: - # If started with Gunicorn, return directly as Gunicorn will call get_application - print("Running under Gunicorn - worker management handled by Gunicorn") - return - - # If not running under Gunicorn, initialize shared data here - from lightrag.kg.shared_storage import initialize_share_data - print("Starting in single-process mode") - initialize_share_data(1) # Force single process mode - + # Create application instance directly instead of using factory function app = create_app(args) diff --git a/lightrag/kg/shared_storage.py b/lightrag/kg/shared_storage.py index 8dc9e1a9..8956d995 100644 --- a/lightrag/kg/shared_storage.py +++ b/lightrag/kg/shared_storage.py @@ -52,7 +52,7 @@ def initialize_share_data(workers: int = 1): # Check if already initialized if _initialized and _initialized.value: is_multiprocess = _is_multiprocess.value - direct_log(f"Process {os.getpid()} storage data already initialized (multiprocess={_is_multiprocess.value})!") + direct_log(f"Process {os.getpid()} storage data already initialized (multiprocess={_is_multiprocess.value})") return _manager = Manager()