提交 4ca605c6 编写于 作者: B barrierye

init_op in thread

上级 8cd7529f
...@@ -60,6 +60,10 @@ class Op(object): ...@@ -60,6 +60,10 @@ class Op(object):
self._outputs = [] self._outputs = []
self._profiler = None self._profiler = None
# only for multithread
self._for_init_op_lock = threading.Lock()
self._succ_init_op = False
def init_profiler(self, profiler): def init_profiler(self, profiler):
self._profiler = profiler self._profiler = profiler
...@@ -180,13 +184,6 @@ class Op(object): ...@@ -180,13 +184,6 @@ class Op(object):
return proces return proces
def start_with_thread(self, client_type): def start_with_thread(self, client_type):
# load user resources
try:
self.init_op()
except Exception as e:
_LOGGER.error(e)
os._exit(-1)
threads = [] threads = []
for concurrency_idx in range(self.concurrency): for concurrency_idx in range(self.concurrency):
t = threading.Thread( t = threading.Thread(
...@@ -330,8 +327,8 @@ class Op(object): ...@@ -330,8 +327,8 @@ class Op(object):
client = None client = None
client_predict_handler = None client_predict_handler = None
# create client based on client_type
try: try:
# create client based on client_type
client = self.init_client(client_type, self._client_config, client = self.init_client(client_type, self._client_config,
self._server_endpoints, self._fetch_names) self._server_endpoints, self._fetch_names)
if client is not None: if client is not None:
...@@ -340,13 +337,18 @@ class Op(object): ...@@ -340,13 +337,18 @@ class Op(object):
_LOGGER.error(log(e)) _LOGGER.error(log(e))
os._exit(-1) os._exit(-1)
if not use_multithread: # load user resources
# load user resources try:
try: if use_multithread:
with self._for_init_op_lock:
if not self._succ_init_op:
self.init_op()
self._succ_init_op = True
else:
self.init_op() self.init_op()
except Exception as e: except Exception as e:
_LOGGER.error(log(e)) _LOGGER.error(log(e))
os._exit(-1) os._exit(-1)
self._is_run = True self._is_run = True
while self._is_run: while self._is_run:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册