[New-bugs-announce] [issue41106] os.scandir() Windows bug dir_entry.stat() not works on file during writing.
report at bugs.python.org
Wed Jun 24 12:55:03 EDT 2020
New submission from Cezary Wagner <cezary.wagner at gmail.com>:
I have problem with change detection of log during writing under Windows (normal fs and windows share). Probably bad order of Windows API calls - no idea.
Test program is attached. You can reproduce it. Try with os.scandir() without os.stats() and os.stat().
Source code responsible for it is probably this -> I do not understand CPython code -> https://github.com/python/cpython/blob/master/Modules/posixmodule.c.
Here is full description - many test was done.
# os.scandir() Windows bug dir_entry.stat() not works on file during writing.
# Such files is for example application log.
# No problem with os.stat()
# Call of os.stat() before os.scandir() -> dir_entry.stat() is workaround.
# Open file during writing other program "fixes" dir_entry.stat().
# Get properties on open file during writing "fixes" dir_entry.stat().
# Notice that I run os.scandir() separately so dir_entry.stat() is not cached.
# Steps to reproduce lack of modification update:
# 1. Close all explorers or other application using PATH (it has impact).
# 2. Set PATH to test folder can be directory or windows share.
# 3. Run program without DO_STAT (False).
# Alternative steps (external app force valid modification date):
# 4. run 'touch' or 'echo' on file should "fix" problem. 'echo' will throw error not matter.
# Alternative scenario (os.stat() force valid modification date - very slow):
# 3. Run program without DO_STAT (True). No problems.
# Error result:
# Modification date from dir_entry.stat() is stalled (not changing after modification)
# if os.stat() or other Windows application not read file.
# Excepted result:
# Modification date from dir_entry.stat() is update from separate calls os.scandir()
# or cached if it is same os.scandir() call.
# Notice that os.scandir() must be call before dir_entry.stat() to avoid caching as described in documentation.
# And this is done but not work on files during writing..
# Ask question if you have since is very hard to find bug.
nosy: Cezary.Wagner, paul.moore, steve.dower, tim.golden, zach.ware
title: os.scandir() Windows bug dir_entry.stat() not works on file during writing.
versions: Python 3.8
Added file: https://bugs.python.org/file49259/s03_dir_entry.py
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce