[issue37935] Improve performance of pathlib.scandir()

hongweipeng report at bugs.python.org
Mon Aug 26 23:45:28 EDT 2019


hongweipeng <hongweichen8888 at sina.com> added the comment:

Scandir() will be close when it iteration is over.You can see ScandirIterator_iternext:

```
static PyObject *
ScandirIterator_iternext(ScandirIterator *iterator)
{
    while (1) {
        ...
    }
    /* Error or no more files */
    ScandirIterator_closedir(iterator);
    return NULL;
}
```

So, `entries = list(scandir(parent_path))` resources in this code can be properly closed.

----------
nosy: +hongweipeng

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37935>
_______________________________________


More information about the Python-bugs-list mailing list