Skip to content

Commit 5b6858c

Browse files
[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.
1 parent 49494c4 commit 5b6858c

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

Lib/test/test_interpreters.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ def run():
6868

6969
class TestBase(unittest.TestCase):
7070

71+
def os_pipe(self):
72+
r, w = os.pipe()
73+
def cleanup():
74+
try:
75+
os.close(w)
76+
except Exception:
77+
pass
78+
try:
79+
os.close(r)
80+
except Exception:
81+
pass
82+
self.addCleanup(cleanup)
83+
return r, w
84+
7185
def tearDown(self):
7286
clean_up_interpreters()
7387

@@ -262,7 +276,7 @@ def test_subinterpreter(self):
262276
self.assertFalse(interp.is_running())
263277

264278
def test_finished(self):
265-
r, w = os.pipe()
279+
r, w = self.os_pipe()
266280
interp = interpreters.create()
267281
interp.run(f"""if True:
268282
import os
@@ -299,8 +313,8 @@ def test_bad_id(self):
299313
interp.is_running()
300314

301315
def test_with_only_background_threads(self):
302-
r_interp, w_interp = os.pipe()
303-
r_thread, w_thread = os.pipe()
316+
r_interp, w_interp = self.os_pipe()
317+
r_thread, w_thread = self.os_pipe()
304318

305319
DONE = b'D'
306320
FINISHED = b'F'
@@ -425,8 +439,8 @@ def test_still_running(self):
425439
self.assertTrue(interp.is_running())
426440

427441
def test_subthreads_still_running(self):
428-
r_interp, w_interp = os.pipe()
429-
r_thread, w_thread = os.pipe()
442+
r_interp, w_interp = self.os_pipe()
443+
r_thread, w_thread = self.os_pipe()
430444

431445
FINISHED = b'F'
432446

@@ -532,8 +546,8 @@ def test_bytes_for_script(self):
532546
interp.run(b'print("spam")')
533547

534548
def test_with_background_threads_still_running(self):
535-
r_interp, w_interp = os.pipe()
536-
r_thread, w_thread = os.pipe()
549+
r_interp, w_interp = self.os_pipe()
550+
r_thread, w_thread = self.os_pipe()
537551

538552
RAN = b'R'
539553
DONE = b'D'

0 commit comments

Comments
 (0)