From 80aa638146d162d258854acc148e926c5c5c153e Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Thu, 4 Nov 2021 06:21:30 +0000 Subject: [PATCH] local predictor+web stop gracefully --- python/paddle_serving_server/util.py | 23 ++++++++++++--------- python/paddle_serving_server/web_service.py | 5 ++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/python/paddle_serving_server/util.py b/python/paddle_serving_server/util.py index 64a36d51..8f0d610a 100644 --- a/python/paddle_serving_server/util.py +++ b/python/paddle_serving_server/util.py @@ -59,16 +59,19 @@ def kill_stop_process_by_pid(command : str, pid : int): if not pid_is_exist(pid): print("Process [%s] has been stopped."%pid) return - try: - if command == "stop": - os.killpg(pid, signal.SIGINT) - elif command == "kill": - os.killpg(pid, signal.SIGKILL) - except ProcessLookupError: - if command == "stop": - os.kill(pid, signal.SIGINT) - elif command == "kill": - os.kill(pid, signal.SIGKILL) + if platform.system() == "Windows": + os.kill(pid, signal.SIGINT) + else: + try: + if command == "stop": + os.killpg(pid, signal.SIGINT) + elif command == "kill": + os.killpg(pid, signal.SIGKILL) + except ProcessLookupError: + if command == "stop": + os.kill(pid, signal.SIGINT) + elif command == "kill": + os.kill(pid, signal.SIGKILL) def dump_pid_file(portList, model): ''' diff --git a/python/paddle_serving_server/web_service.py b/python/paddle_serving_server/web_service.py index 52e394b2..fd1810e3 100755 --- a/python/paddle_serving_server/web_service.py +++ b/python/paddle_serving_server/web_service.py @@ -28,6 +28,7 @@ import os from paddle_serving_server import pipeline from paddle_serving_server.pipeline import Op from paddle_serving_server.serve import format_gpu_to_strlist +from paddle_serving_server.util import dump_pid_file def port_is_available(port): @@ -260,7 +261,9 @@ class WebService(object): self.gpu_multi_stream = gpu_multi_stream self.op_num = op_num self.op_max_batch = op_max_batch - + + # record port and pid info for stopping process + dump_pid_file([self.port], "web_service") # if gpuid != None, we will use gpuid first. # otherwise, keep the self.gpus unchanged. # maybe self.gpus is set by the Function set_gpus. -- GitLab