Message370491
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. |
|
Date |
User |
Action |
Args |
2020-05-31 17:50:02 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, gvanrossum, roysmith, steven.daprano, r.david.murray, docs@python, Gumnos, Roger Erens |
2020-05-31 17:50:02 | serhiy.storchaka | set | messageid: <1590947402.43.0.653333084413.issue22167@roundup.psfhosted.org> |
2020-05-31 17:50:02 | serhiy.storchaka | link | issue22167 messages |
2020-05-31 17:50:02 | serhiy.storchaka | create | |
|