From 43dce09f6f99a7018594c89c15868ecad3b3e2d7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 10 Jun 2019 22:30:23 +0200 Subject: [PATCH] bpo-36402: Fix test_threading.test_threads_join_2() Fix test_threading.test_threads_join_2(): run the test into a subprocess, rather than in a subinterpreter, to avoid a race condition. --- Lib/test/test_threading.py | 6 ++++-- .../next/Tests/2019-06-10-22-45-26.bpo-36402.QqZnfC.rst | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2019-06-10-22-45-26.bpo-36402.QqZnfC.rst diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 6ac4ea9623de0d..512789ce5cffce 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -888,8 +888,10 @@ def f(): os.write(%d, b"x") threading.Thread(target=f).start() """ % (w,) - ret = test.support.run_in_subinterp(code) - self.assertEqual(ret, 0) + import subprocess + proc = subprocess.run([sys.executable, "-c", code], stderr=subprocess.PIPE, pass_fds=[w]) + self.assertEqual(proc.stderr, b'', proc) + self.assertEqual(proc.returncode, 0, proc) # The thread was joined properly. self.assertEqual(os.read(r, 1), b"x") diff --git a/Misc/NEWS.d/next/Tests/2019-06-10-22-45-26.bpo-36402.QqZnfC.rst b/Misc/NEWS.d/next/Tests/2019-06-10-22-45-26.bpo-36402.QqZnfC.rst new file mode 100644 index 00000000000000..9a96c5396b6d17 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-06-10-22-45-26.bpo-36402.QqZnfC.rst @@ -0,0 +1,2 @@ +Fix ``test_threading.test_threads_join_2()``: run the test into a +subprocess, rather than in a subinterpreter, to avoid a race condition.