Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:
Yes, for the pattern 'a*/b*/c*' you will have an open file descriptor for every component with metacharacters: for a in scandir('.'): if fnmatch(a.name, 'a*'): for b in scandir(a.path): if fnmatch(b.name, 'b*'): for c in scandir(b.path): if fnmatch(c.name, 'c*'): yield c.path You can have hundreds nested directories. Looks not bad, because by default the limit on the number of file descriptors is 1024 on Linux. But imagine you run a server and it handles tens requests simultaneously. Some of them or all of them will fail, and not just return an error, but return an incorrect result, because all OSError, including "Too many open files", are silenced in glob(). Also all these file descriptors will not be closed until you finish the iteration, or, in case of error, until the garbage collector close them (because interrupted generators tend to create reference loops). So it is vital to close the file descriptor before you open other file descriptors in the recursion. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue22167> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com