[issue41106] os.scandir() Windows bug dir_entry.stat() not works on file during writing.

Cezary Wagner report at bugs.python.org
Wed Jul 1 07:25:50 EDT 2020


Cezary Wagner <cezary.wagner at gmail.com> added the comment:

As far as I know os.stat() resets d.stat() maybe should be added some option to d.stat() to force update(). d.stat(nt_force_update=True).

I am not sure if os.path.getmtime() can reset d.stat().

os.stat() is 2x times slower than os.path.getmtime() and os.path.getmtime is 16x slower than d.stat(). MAJOR PROBLEM is PERFORMANCE of os.stat() since for directories with 1000 files it takes big number of seconds to read all stats - something wrong is here I think since Windows Explorer is doing it very fast.

So I can not use os.stat() ONLY and it complicates code since I need to use os.stat() after d.stat() if files is OLDER THAN because if I use os.stat() the most program time will be these calls.

Do you know which code makes such reset of d.stat()?

If there is not possible optimization of there is need DOCUMENTATION update because it is really hard to understand why it is not working under windows some REMARKS can help me and others.

I have still believe that some optimization is possible for Windows.

Maybe it can be force to read stat by os.scandir(force_scan_stat=True) so all directory entries will be have cached stats before d.stat() is called. It can be faster I think since less calls from Python and probably better Windows API for it and same for Linux.

I will study C code later if it is possible or write some snippet.

----------

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


More information about the Python-bugs-list mailing list