Skip to content

Commit fd4a42d

Browse files
authored
gh-82116: add comment explaining use of list(scandir_it) in pathlib. (GH-94939)
Automerge-Triggered-By: GH:brettcannon
1 parent 742d461 commit fd4a42d

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Lib/pathlib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ def __init__(self, pat, child_parts, flavour):
299299

300300
def _select_from(self, parent_path, is_dir, exists, scandir):
301301
try:
302+
# We must close the scandir() object before proceeding to
303+
# avoid exhausting file descriptors when globbing deep trees.
302304
with scandir(parent_path) as scandir_it:
303305
entries = list(scandir_it)
304306
for entry in entries:
@@ -330,6 +332,8 @@ def __init__(self, pat, child_parts, flavour):
330332
def _iterate_directories(self, parent_path, is_dir, scandir):
331333
yield parent_path
332334
try:
335+
# We must close the scandir() object before proceeding to
336+
# avoid exhausting file descriptors when globbing deep trees.
333337
with scandir(parent_path) as scandir_it:
334338
entries = list(scandir_it)
335339
for entry in entries:

0 commit comments

Comments
 (0)