From 029a0ec00d3bfb45c5d67f4ec463ec22ef25a871 Mon Sep 17 00:00:00 2001 From: Kaipeng Deng Date: Fri, 21 Feb 2020 10:31:50 +0800 Subject: [PATCH] kill process group when main process exit (#136) --- ppdet/data/parallel_map.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ppdet/data/parallel_map.py b/ppdet/data/parallel_map.py index 9e55f7fda..7517157cd 100644 --- a/ppdet/data/parallel_map.py +++ b/ppdet/data/parallel_map.py @@ -19,6 +19,7 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function +import os import sys import six if six.PY3: @@ -281,3 +282,13 @@ class ParallelMap(object): # FIXME(dengkaipeng): fix me if you have better impliment # handle terminate reader process, do not print stack frame signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit()) + + +def _term_group(sig_num, frame): + pid = os.getpid() + pg = os.getpgid(os.getpid()) + logger.info("main proc {} exit, kill process group " "{}".format(pid, pg)) + os.killpg(pg, signal.SIGKILL) + + +signal.signal(signal.SIGINT, _term_group) -- GitLab