From a6fc0f6d683d17cffb8a29db9ca040a1ae2d7239 Mon Sep 17 00:00:00 2001 From: MRXLT Date: Thu, 28 May 2020 05:47:55 +0000 Subject: [PATCH] add lock for bin download --- python/paddle_serving_server/__init__.py | 7 +++++++ python/paddle_serving_server_gpu/__init__.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/python/paddle_serving_server/__init__.py b/python/paddle_serving_server/__init__.py index 3cb96a8f..7356de2c 100644 --- a/python/paddle_serving_server/__init__.py +++ b/python/paddle_serving_server/__init__.py @@ -23,6 +23,7 @@ import paddle_serving_server as paddle_serving_server from .version import serving_server_version from contextlib import closing import collections +import fcntl class OpMaker(object): @@ -322,6 +323,10 @@ class Server(object): bin_url = "https://paddle-serving.bj.bcebos.com/bin/" + tar_name self.server_path = os.path.join(self.module_path, floder_name) + #acquire lock + version_file = open("{}/version.py".format(self.module_path), "r") + fcntl.flock(version_file, fcntl.LOCK_EX) + if not os.path.exists(self.server_path): print('Frist time run, downloading PaddleServing components ...') r = os.system('wget ' + bin_url + ' --no-check-certificate') @@ -345,6 +350,8 @@ class Server(object): foemat(self.module_path)) finally: os.remove(tar_name) + #release lock + version_file.close() os.chdir(self.cur_path) self.bin_path = self.server_path + "/serving" diff --git a/python/paddle_serving_server_gpu/__init__.py b/python/paddle_serving_server_gpu/__init__.py index dc9f2b85..d4631141 100644 --- a/python/paddle_serving_server_gpu/__init__.py +++ b/python/paddle_serving_server_gpu/__init__.py @@ -25,7 +25,7 @@ from .version import serving_server_version from contextlib import closing import argparse import collections -import multiprocessing +import fcntl def serve_args(): @@ -178,7 +178,6 @@ class Server(object): self.use_local_bin = False self.gpuid = 0 self.model_config_paths = None # for multi-model in a workflow - self.lock = multiprocessing.Lock() def set_max_concurrency(self, concurrency): self.max_concurrency = concurrency @@ -339,7 +338,6 @@ class Server(object): # print config here def download_bin(self): - self.lock.acquire() os.chdir(self.module_path) need_download = False device_version = "serving-gpu-" @@ -350,6 +348,11 @@ class Server(object): download_flag = "{}/{}.is_download".format(self.module_path, folder_name) + + #acquire lock + version_file = open("{}/version.py".format(self.module_path), "r") + fcntl.flock(version_file, fcntl.LOCK_EX) + if os.path.exists(download_flag): os.chdir(self.cur_path) self.bin_path = self.server_path + "/serving" @@ -380,9 +383,10 @@ class Server(object): format(self.module_path)) finally: os.remove(tar_name) + #release lock + version_file.cloes() os.chdir(self.cur_path) self.bin_path = self.server_path + "/serving" - self.lock.release() def prepare_server(self, workdir=None, port=9292, device="cpu"): if workdir == None: -- GitLab