1 # Copyright (c) 2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 import multiprocessing
19 LOG = logging.getLogger(__name__)
22 def check_if_process_failed(proc, timeout=1):
25 # Only abort if the process aborted
26 if proc.exitcode is not None and proc.exitcode > 0:
27 raise RuntimeError("{} exited with status {}".format(proc.name, proc.exitcode))
30 def terminate_children(timeout=3):
31 current_proccess = multiprocessing.current_process()
32 active_children = multiprocessing.active_children()
33 if not active_children:
34 LOG.debug("no children to terminate")
36 for child in active_children:
37 LOG.debug("%s %s %s, child: %s %s", current_proccess.name, current_proccess.pid,
38 os.getpid(), child, child.pid)
39 LOG.debug("joining %s", child)
42 active_children = multiprocessing.active_children()
43 if not active_children:
44 LOG.debug("no children to terminate")
45 for child in active_children:
46 LOG.debug("%s %s %s, after terminate child: %s %s", current_proccess.name,
47 current_proccess.pid, os.getpid(), child, child.pid)