Improve Gunicorn support and cleanup shared storage initialization
• Move Gunicorn check before other startup • Improve startup flow organization
This commit is contained in:
@@ -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()
|
||||||
@@ -483,17 +488,6 @@ def main():
|
|||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
@@ -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()
|
||||||
|
Reference in New Issue
Block a user