diff --git a/ppdet/data/parallel_map.py b/ppdet/data/parallel_map.py index 9e55f7fdabad5d32022c93204ec2414e52a136d5..7517157cdbeaf597fc7c5cb4c57db4153c90fbf5 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)