Serhiy Storchaka added the comment: > os.scandir() is called recursively in the last patch and the file descriptors > are not closed until returning from the recursion.
No, os.scandir() is called non-recursively in _iterdir(), and since _iterdir() results are always accumulated in a list, a recursion starts only after exhausting the os.scandir() iterator and closing the file descriptor. We need first to resolve issue25994 to close the file descriptor explicitly. > The glob functions should fail explicitly when scandir() raises OSERROR with > posix errno set to EMFILE (The process has too many files open), or even > better, silently ignore only the PermissionError exception instead of > ignoring OSERROR. Patched code passes existing tests. Do you have additional tests? > Is the call to entry.is_symlink() in _iterdir() necessary since is_dir() > follows symlinks ? Ah, I thought is_dir() doesn't follow symlinks. Yes, now the call to entry.is_symlink() is not necessary. > If _iterdir() would yield the DirEntry instance instead of DirEntry.name, > then _rlistdir() could use x.is_dir() to know whether it is correct to > iterate over _rlistdir(x.path, dironly) Yes, but this can complicate the rest of the code. _rlistdir() is called with dironly=False only when the pattern ends with '**'. I'm not sure this is enough important case for optimization. In most cases '**' is used in the middle of the pattern, and all names yielded by _iterdir() are directory names (or broken symlinks). ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25596> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com