diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-11-28 19:42:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-28 19:42:49 (GMT) |
commit | 5b6858c22049b467c844620bf591c3b1bca629d6 (patch) | |
tree | fabbae49146b5c980d7fa1823592f60f638abfcd | |
parent | 49494c472161976dec483eb09e1bad0378758d3f (diff) | |
download | cpython-5b6858c22049b467c844620bf591c3b1bca629d6.zip cpython-5b6858c22049b467c844620bf591c3b1bca629d6.tar.gz cpython-5b6858c22049b467c844620bf591c3b1bca629d6.tar.bz2 |
[3.12] gh-105716: Fix Refleaks in test_interpreters (gh-112500)
gh-110707 (0122b4d) added some tests that didn't close file descriptors they created, leading to failures on the refleak buildbots. This closes the leaking file descriptors, resolving the failure.
-rw-r--r-- | Lib/test/test_interpreters.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/Lib/test/test_interpreters.py b/Lib/test/test_interpreters.py index cc4f400..2b0cff5 100644 --- a/Lib/test/test_interpreters.py +++ b/Lib/test/test_interpreters.py @@ -68,6 +68,20 @@ def _running(interp): class TestBase(unittest.TestCase): + def os_pipe(self): + r, w = os.pipe() + def cleanup(): + try: + os.close(w) + except Exception: + pass + try: + os.close(r) + except Exception: + pass + self.addCleanup(cleanup) + return r, w + def tearDown(self): clean_up_interpreters() @@ -262,7 +276,7 @@ class TestInterpreterIsRunning(TestBase): self.assertFalse(interp.is_running()) def test_finished(self): - r, w = os.pipe() + r, w = self.os_pipe() interp = interpreters.create() interp.run(f"""if True: import os @@ -299,8 +313,8 @@ class TestInterpreterIsRunning(TestBase): interp.is_running() def test_with_only_background_threads(self): - r_interp, w_interp = os.pipe() - r_thread, w_thread = os.pipe() + r_interp, w_interp = self.os_pipe() + r_thread, w_thread = self.os_pipe() DONE = b'D' FINISHED = b'F' @@ -425,8 +439,8 @@ class TestInterpreterClose(TestBase): self.assertTrue(interp.is_running()) def test_subthreads_still_running(self): - r_interp, w_interp = os.pipe() - r_thread, w_thread = os.pipe() + r_interp, w_interp = self.os_pipe() + r_thread, w_thread = self.os_pipe() FINISHED = b'F' @@ -532,8 +546,8 @@ class TestInterpreterRun(TestBase): interp.run(b'print("spam")') def test_with_background_threads_still_running(self): - r_interp, w_interp = os.pipe() - r_thread, w_thread = os.pipe() + r_interp, w_interp = self.os_pipe() + r_thread, w_thread = self.os_pipe() RAN = b'R' DONE = b'D' |