!13314 [MD][bugfix][multi-process][retinaface_resnet50] Fix retinaface resnet50 ctrl+c hang problem

From: @xiefangqi
Reviewed-by: @liucunwei,@heleiwang
Signed-off-by: @liucunwei
pull/13314/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit 7625a0d108

@ -2195,16 +2195,16 @@ def _pyfunc_worker_exec(index, op_id, mapping, lock, record, *args):
""" """
Internal function for call certain pyfunc in python process. Internal function for call certain pyfunc in python process.
""" """
try: # Some threads in multiprocess.pool can't process sigint signal,
if record: # and will occur hang problem, so ctrl+c will pass to parent process.
pid = os.getpid() signal.signal(signal.SIGINT, signal.SIG_IGN)
with lock: if record:
data = mapping[op_id] pid = os.getpid()
data[1].add(pid) with lock:
mapping[op_id] = data data = mapping[op_id]
return _GLOBAL_PYFUNC_LIST[index](*args) data[1].add(pid)
except KeyboardInterrupt: mapping[op_id] = data
raise Exception("Multiprocess MapOp worker receives KeyboardInterrupt") return _GLOBAL_PYFUNC_LIST[index](*args)
# PythonCallable wrapper for multiprocess pyfunc # PythonCallable wrapper for multiprocess pyfunc
@ -3262,6 +3262,10 @@ def _generator_worker_loop(dataset, idx_queue, result_queue, eof, is_multiproces
try: try:
idx = idx_queue.get(timeout=1) idx = idx_queue.get(timeout=1)
except KeyboardInterrupt: except KeyboardInterrupt:
if is_multiprocessing:
eof.set()
idx_queue.cancel_join_thread()
result_queue.cancel_join_thread()
raise Exception("Generator worker receives KeyboardInterrupt.") raise Exception("Generator worker receives KeyboardInterrupt.")
except queue.Empty: except queue.Empty:
if eof.is_set(): if eof.is_set():
@ -3288,6 +3292,10 @@ def _generator_worker_loop(dataset, idx_queue, result_queue, eof, is_multiproces
try: try:
result_queue.put(result, timeout=5) result_queue.put(result, timeout=5)
except KeyboardInterrupt: except KeyboardInterrupt:
if is_multiprocessing:
eof.set()
idx_queue.cancel_join_thread()
result_queue.cancel_join_thread()
raise Exception("Generator worker receives KeyboardInterrupt.") raise Exception("Generator worker receives KeyboardInterrupt.")
except queue.Full: except queue.Full:
if eof.is_set(): if eof.is_set():

Loading…
Cancel
Save