summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2022-07-20 21:34:13 (GMT)
committerGitHub <noreply@github.com>2022-07-20 21:34:13 (GMT)
commitfd4a42d8902107647f9b7b0b6a6247e7d5253fa7 (patch)
tree4c1772ef9453a0994ca3cd914b3e85f78ae6da5a
parent742d4614e1a645d765dbf76c19bd9a818239b1cb (diff)
downloadcpython-fd4a42d8902107647f9b7b0b6a6247e7d5253fa7.zip
cpython-fd4a42d8902107647f9b7b0b6a6247e7d5253fa7.tar.gz
cpython-fd4a42d8902107647f9b7b0b6a6247e7d5253fa7.tar.bz2
gh-82116: add comment explaining use of `list(scandir_it)` in pathlib. (GH-94939)
Automerge-Triggered-By: GH:brettcannon
-rw-r--r--Lib/pathlib.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 69e7d55..62dd0fa 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -299,6 +299,8 @@ class _WildcardSelector(_Selector):
def _select_from(self, parent_path, is_dir, exists, scandir):
try:
+ # We must close the scandir() object before proceeding to
+ # avoid exhausting file descriptors when globbing deep trees.
with scandir(parent_path) as scandir_it:
entries = list(scandir_it)
for entry in entries:
@@ -330,6 +332,8 @@ class _RecursiveWildcardSelector(_Selector):
def _iterate_directories(self, parent_path, is_dir, scandir):
yield parent_path
try:
+ # We must close the scandir() object before proceeding to
+ # avoid exhausting file descriptors when globbing deep trees.
with scandir(parent_path) as scandir_it:
entries = list(scandir_it)
for entry in entries: