This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.utime(..., None) has poor resolution on Windows
Type: behavior Stage:
Components: Library (Lib), Windows Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brian.curtin, larry, loewis, pitrou, python-dev, steve.dower, tim.golden, tim.peters, vstinner
Priority: normal Keywords: patch

Created on 2013-11-23 01:15 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
utime_win.patch pitrou, 2013-11-23 13:37 review
Messages (5)
msg203943 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-23 01:15
os.utime() uses the following code when times is None under Windows:

        SYSTEMTIME now;
        GetSystemTime(&now);
        if (!SystemTimeToFileTime(&now, &mtime) ||
            !SystemTimeToFileTime(&now, &atime)) {
            PyErr_SetFromWindowsErr(0);
            goto exit;
        }

The problem is GetSystemTime has poor resolution (milliseconds). Instead, it could call GetSystemTimeAsFileTime which writes directly into a FILETIME structure, and potentially (?) has better resolution.

(according to a comment on MSDN, "Resolution on Windows 7 seems to be sub-millisecond": http://msdn.microsoft.com/en-us/library/windows/desktop/ms724397%28v=vs.85%29.aspx )
msg204007 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-23 13:33
Here is a patch.
msg204009 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-23 13:37
Redoing (indentation issue).
msg204022 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-23 14:02
utime_win.patch looks good to me.
msg204027 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-23 14:23
New changeset 6a9e262c5423 by Antoine Pitrou in branch 'default':
Issue #19727: os.utime(..., None) is now potentially more precise under Windows.
http://hg.python.org/cpython/rev/6a9e262c5423
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 63926
2013-11-23 14:23:45pitrousetstatus: open -> closed
resolution: fixed
2013-11-23 14:23:33python-devsetnosy: + python-dev
messages: + msg204027
2013-11-23 14:02:11vstinnersetnosy: + vstinner
messages: + msg204022
2013-11-23 13:41:54pitrousetfiles: - utime_win.patch
2013-11-23 13:37:23pitrousetfiles: + utime_win.patch

messages: + msg204009
2013-11-23 13:33:54pitrousetfiles: + utime_win.patch
keywords: + patch
messages: + msg204007
2013-11-23 01:15:52pitroucreate