Skip to content

Commit

Permalink
[3.12] gh-105716: Fix Refleaks in test_interpreters (gh-112500)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ericsnowcurrently authored Nov 28, 2023
1 parent 49494c4 commit 5b6858c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions Lib/test/test_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ def run():

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()

Expand Down Expand Up @@ -262,7 +276,7 @@ def test_subinterpreter(self):
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
Expand Down Expand Up @@ -299,8 +313,8 @@ def test_bad_id(self):
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'
Expand Down Expand Up @@ -425,8 +439,8 @@ def test_still_running(self):
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'

Expand Down Expand Up @@ -532,8 +546,8 @@ def test_bytes_for_script(self):
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'
Expand Down

0 comments on commit 5b6858c

Please sign in to comment.