Skip to content

Commit

Permalink
update msi entr
Browse files Browse the repository at this point in the history
  • Loading branch information
Ying Chen committed Feb 7, 2024
1 parent 9a3aea5 commit bd9937b
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/promptflow/promptflow/_sdk/_service/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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(
Expand Down

0 comments on commit bd9937b

Please sign in to comment.