[Python-checkins] gh-82116: add comment explaining use of `list(scandir_it)` in pathlib. (GH-94939)

miss-islington webhook-mailer at python.org
Wed Jul 20 17:34:22 EDT 2022


https://github.com/python/cpython/commit/fd4a42d8902107647f9b7b0b6a6247e7d5253fa7
commit: fd4a42d8902107647f9b7b0b6a6247e7d5253fa7
branch: main
author: Barney Gale <barney.gale at gmail.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-07-20T14:34:13-07:00
summary:

gh-82116: add comment explaining use of `list(scandir_it)` in pathlib. (GH-94939)



Automerge-Triggered-By: GH:brettcannon

files:
M Lib/pathlib.py

diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 69e7d558a056f..62dd0fa1b1237 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -299,6 +299,8 @@ def __init__(self, pat, child_parts, flavour):
 
     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 @@ def __init__(self, pat, child_parts, flavour):
     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:



More information about the Python-checkins mailing list