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(