Improve Gunicorn support and cleanup shared storage initialization

• Move Gunicorn check before other startup
• Improve startup flow organization
This commit is contained in:
yangdx
2025-02-27 14:13:42 +08:00
parent 7aec78833c
commit 03d05b094d
2 changed files with 8 additions and 14 deletions

View File

@@ -470,8 +470,13 @@ def configure_logging():
def main(): 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() freeze_support()
args = parse_args() args = parse_args()
@@ -482,18 +487,7 @@ def main():
configure_logging() configure_logging()
display_splash_screen(args) 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 # Create application instance directly instead of using factory function
app = create_app(args) app = create_app(args)

View File

@@ -52,7 +52,7 @@ def initialize_share_data(workers: int = 1):
# Check if already initialized # Check if already initialized
if _initialized and _initialized.value: if _initialized and _initialized.value:
is_multiprocess = _is_multiprocess.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 return
_manager = Manager() _manager = Manager()