From e5034707003990da2e513774f66338f3836c0a92 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Thu, 7 Jan 2021 06:18:03 -0600 Subject: [PATCH] try multi times for sys.exit (#30188) --- .../test_imperative_signal_handler.py | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_imperative_signal_handler.py b/python/paddle/fluid/tests/unittests/test_imperative_signal_handler.py index 4941e9dec5..991d4058d0 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_signal_handler.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_signal_handler.py @@ -41,18 +41,27 @@ class TestDygraphDataLoaderSingalHandler(unittest.TestCase): def test_child_process_exit_with_error(self): def __test_process__(): core._set_process_signal_handler() - os._exit(os.EX_DATAERR) - + sys.exit(1) + + def try_except_exit(): + exception = None + try: + test_process = multiprocessing.Process(target=__test_process__) + test_process.start() + + set_child_signal_handler(id(self), test_process.pid) + time.sleep(5) + except SystemError as ex: + self.assertIn("Fatal", cpt.get_exception_message(ex)) + exception = ex + return exception + + try_time = 10 exception = None - try: - test_process = multiprocessing.Process(target=__test_process__) - test_process.start() - - set_child_signal_handler(id(self), test_process.pid) - time.sleep(10) - except SystemError as ex: - self.assertIn("Fatal", cpt.get_exception_message(ex)) - exception = ex + for i in range(try_time): + exception = try_except_exit() + if exception is not None: + break self.assertIsNotNone(exception) -- GitLab