From d2e5720f7470ab10b16ea6e13c3d0577ba6cc767 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 27 Mar 2020 20:17:11 +0100 Subject: [PATCH] bpo-40068: test_reinit_tls_after_fork() detects crashes test_reinit_tls_after_fork() of test_threading now checks if a child process crashed in os.fork(). --- Lib/test/test_threading.py | 14 +++++++++++--- .../Tests/2020-03-27-20-23-31.bpo-40068.HucS3F.rst | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2020-03-27-20-23-31.bpo-40068.HucS3F.rst diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index da17e1281d9867..e0bd2c33f2ee7f 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -897,14 +897,18 @@ def test_reinit_tls_after_fork(self): # Issue #13817: fork() would deadlock in a multithreaded program with # the ad-hoc TLS implementation. + all_status = [] + def do_fork_and_wait(): # just fork a child process and wait it pid = os.fork() - if pid > 0: - os.waitpid(pid, 0) - else: + if not pid: + # child process: just exit os._exit(0) + pid, status = os.waitpid(pid, 0) + all_status.append(status) + # start a bunch of threads that will fork() child processes threads = [] for i in range(16): @@ -915,6 +919,10 @@ def do_fork_and_wait(): for t in threads: t.join() + # ensure that all child processes completed successfully (no crash) + for status in all_status: + self.assertEqual(status, 0) + @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") def test_clear_threads_states_after_fork(self): # Issue #17094: check that threads states are cleared after fork() diff --git a/Misc/NEWS.d/next/Tests/2020-03-27-20-23-31.bpo-40068.HucS3F.rst b/Misc/NEWS.d/next/Tests/2020-03-27-20-23-31.bpo-40068.HucS3F.rst new file mode 100644 index 00000000000000..bd77992aae309d --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-03-27-20-23-31.bpo-40068.HucS3F.rst @@ -0,0 +1,2 @@ +test_reinit_tls_after_fork() of test_threading now checks if a child process +crashed in os.fork().