From 5367a64230390945d1901870e4e65512a66f11fb Mon Sep 17 00:00:00 2001 From: jiangshuqiang Date: Fri, 19 Mar 2021 10:20:56 +0800 Subject: [PATCH] fix the multiprocessing context from fork to forkserver --- mindinsight/utils/computing_resource_mgr.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/mindinsight/utils/computing_resource_mgr.py b/mindinsight/utils/computing_resource_mgr.py index ed9067d4..fe5778a8 100644 --- a/mindinsight/utils/computing_resource_mgr.py +++ b/mindinsight/utils/computing_resource_mgr.py @@ -13,12 +13,10 @@ # limitations under the License. # ============================================================================ """Compute resource manager.""" -import sys import fractions import math import threading from concurrent import futures -import signal import multiprocessing from mindinsight.utils.log import setup_logger @@ -26,7 +24,7 @@ from mindinsight.utils.constant import GeneralErrors from mindinsight.utils.exceptions import MindInsightException -_MP_CONTEXT = multiprocessing.get_context(method="fork") +_MP_CONTEXT = multiprocessing.get_context(method="forkserver") terminating = False @@ -51,18 +49,7 @@ class ComputingResourceManager: for ind in range(self._executors_cnt) } self._remaining_executors = len(self._executors) - - def initializer(): - origin_handler = signal.getsignal(signal.SIGTERM) - - def handler(sig, frame): - origin_handler(sig, frame) - sys.exit(0) - - signal.signal(signal.SIGTERM, handler) - - self._backend = futures.ProcessPoolExecutor(max_workers=max_processes_cnt, mp_context=_MP_CONTEXT, - initializer=initializer) + self._backend = futures.ProcessPoolExecutor(max_workers=max_processes_cnt, mp_context=_MP_CONTEXT) self.logger = setup_logger("utils", "utils") self.logger.info("Initialized ComputingResourceManager with executors_cnt=%s, max_processes_cnt=%s.", executors_cnt, max_processes_cnt)