Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stop leaking file descriptors.
  • Loading branch information
ericsnowcurrently committed Oct 3, 2023
commit b2919311defe8e2ff29cac14e54d0d3bf49f0121
25 changes: 18 additions & 7 deletions Lib/test/test_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ def run():

class TestBase(unittest.TestCase):

def pipe(self):
def ensure_closed(fd):
try:
os.close(fd)
except OSError:
pass
r, w = os.pipe()
self.addCleanup(lambda: ensure_closed(r))
self.addCleanup(lambda: ensure_closed(w))
return r, w

def tearDown(self):
clean_up_interpreters()

Expand Down Expand Up @@ -262,7 +273,7 @@ def test_subinterpreter(self):
self.assertFalse(interp.is_running())

def test_finished(self):
r, w = os.pipe()
r, w = self.pipe()
interp = interpreters.create()
interp.run(f"""if True:
import os
Expand Down Expand Up @@ -299,8 +310,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.pipe()
r_thread, w_thread = self.pipe()

DONE = b'D'
FINISHED = b'F'
Expand Down Expand Up @@ -425,8 +436,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.pipe()
r_thread, w_thread = self.pipe()

FINISHED = b'F'

Expand Down Expand Up @@ -532,8 +543,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.pipe()
r_thread, w_thread = self.pipe()

RAN = b'R'
DONE = b'D'
Expand Down