]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-82116: add comment explaining use of `list(scandir_it)` in pathlib. (GH-94939)
authorBarney Gale <barney.gale@gmail.com>
Wed, 20 Jul 2022 21:34:13 +0000 (22:34 +0100)
committerGitHub <noreply@github.com>
Wed, 20 Jul 2022 21:34:13 +0000 (14:34 -0700)
Automerge-Triggered-By: GH:brettcannon
Lib/pathlib.py

index 69e7d558a056fc48093fef7e6300de9fced9554b..62dd0fa1b1237b6379fca3e56fc43a2f2accbddb 100644 (file)
@@ -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: