From bd9937bca6bb2c6a19d904b3ab30e3e4fa573013 Mon Sep 17 00:00:00 2001 From: Ying Chen <2601502859@qq.com> Date: Wed, 7 Feb 2024 15:50:42 +0800 Subject: [PATCH] update msi entr --- .../promptflow/_sdk/_service/entry.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/promptflow/promptflow/_sdk/_service/entry.py b/src/promptflow/promptflow/_sdk/_service/entry.py index d2596218296f..719f7f43fb15 100644 --- a/src/promptflow/promptflow/_sdk/_service/entry.py +++ b/src/promptflow/promptflow/_sdk/_service/entry.py @@ -28,11 +28,11 @@ app = None -def get_app(environ, start_response): +def get_app(): global app if app is None: app, _ = create_app() - return app.wsgi_app(environ, start_response) + return app def add_start_service_action(subparsers): @@ -70,7 +70,7 @@ def start_service(args): # User Agent will be set based on header in request, so not set globally here. os.environ[PF_NO_INTERACTIVE_LOGIN] = "true" port = args.port - app, _ = create_app() + get_app() def validate_port(port, force_start): if is_port_in_use(port): @@ -88,15 +88,30 @@ def validate_port(port, force_start): port = get_port_from_config(create_if_not_exists=True) validate_port(port, args.force) # Set host to localhost, only allow request from localhost. - cmd = ["waitress-serve", f"--listen=127.0.0.1:{port}", "promptflow._sdk._service.entry:get_app"] + cmd = [ + "-m", + "waitress", + "--host", + "127.0.0.1", + f"--port={port}", + "--call", + "promptflow._sdk._service.entry:get_app", + ] + if sys.executable.endswith("pfcli.exe"): + cmd = ["python"] + cmd + else: + cmd = [sys.executable] + cmd if args.synchronous: subprocess.call(cmd) else: # Start a pfs process using detach mode if platform.system() == "Windows": - subprocess.Popen(cmd, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) + if sys.executable.endswith("pfcli.exe"): + os.spawnv(os.P_DETACH, "python", cmd) + else: + os.spawnv(os.P_DETACH, sys.executable, cmd) else: - subprocess.Popen(cmd, start_new_session=True) + os.system(" ".join(["nohup"] + cmd + ["&"])) is_healthy = check_pfs_service_status(port) if is_healthy: app.logger.info(