提交 30f1b53c 编写于 作者: M MRXLT

add lock for bin download

上级 8292b8a4
......@@ -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"
......
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册