mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
[3.13] GH-89727: Fix FD leak on os.fwalk()
generator finalization. (GH-119766) (#119767)
GH-89727: Fix FD leak on `os.fwalk()` generator finalization. (GH-119766) Follow-up to3c890b50
. Ensure we `os.close()` open file descriptors when the `os.fwalk()` generator is finalized. (cherry picked from commita5fef800d3
) Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
810a09ad37
commit
083bf3ad17
2 changed files with 30 additions and 2 deletions
|
@ -1685,6 +1685,27 @@ class FwalkTests(WalkTests):
|
|||
self.addCleanup(os.close, newfd)
|
||||
self.assertEqual(newfd, minfd)
|
||||
|
||||
@unittest.skipIf(
|
||||
support.is_emscripten, "Cannot dup stdout on Emscripten"
|
||||
)
|
||||
@unittest.skipIf(
|
||||
support.is_android, "dup return value is unpredictable on Android"
|
||||
)
|
||||
def test_fd_finalization(self):
|
||||
# Check that close()ing the fwalk() generator closes FDs
|
||||
def getfd():
|
||||
fd = os.dup(1)
|
||||
os.close(fd)
|
||||
return fd
|
||||
for topdown in (False, True):
|
||||
old_fd = getfd()
|
||||
it = self.fwalk(os_helper.TESTFN, topdown=topdown)
|
||||
self.assertEqual(getfd(), old_fd)
|
||||
next(it)
|
||||
self.assertGreater(getfd(), old_fd)
|
||||
it.close()
|
||||
self.assertEqual(getfd(), old_fd)
|
||||
|
||||
# fwalk() keeps file descriptors open
|
||||
test_walk_many_open_files = None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue