Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.utime(..., None) has poor resolution on Windows #63926

Closed
pitrou opened this issue Nov 23, 2013 · 5 comments
Closed

os.utime(..., None) has poor resolution on Windows #63926

pitrou opened this issue Nov 23, 2013 · 5 comments
Labels
OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented Nov 23, 2013

BPO 19727
Nosy @tim-one, @loewis, @pitrou, @vstinner, @larryhastings, @tjguk, @briancurtin, @zooba
Files
  • utime_win.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2013-11-23.14:23:45.183>
    created_at = <Date 2013-11-23.01:15:52.139>
    labels = ['type-bug', 'library', 'OS-windows']
    title = 'os.utime(..., None) has poor resolution on Windows'
    updated_at = <Date 2013-11-23.14:23:45.183>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2013-11-23.14:23:45.183>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-11-23.14:23:45.183>
    closer = 'pitrou'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2013-11-23.01:15:52.139>
    creator = 'pitrou'
    dependencies = []
    files = ['32797']
    hgrepos = []
    issue_num = 19727
    keywords = ['patch']
    message_count = 5.0
    messages = ['203943', '204007', '204009', '204022', '204027']
    nosy_count = 9.0
    nosy_names = ['tim.peters', 'loewis', 'pitrou', 'vstinner', 'larry', 'tim.golden', 'brian.curtin', 'python-dev', 'steve.dower']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue19727'
    versions = ['Python 3.4']

    @pitrou
    Copy link
    Member Author

    pitrou commented Nov 23, 2013

    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 )

    @pitrou pitrou added stdlib Python modules in the Lib dir OS-windows type-bug An unexpected behavior, bug, or error labels Nov 23, 2013
    @pitrou
    Copy link
    Member Author

    pitrou commented Nov 23, 2013

    Here is a patch.

    @pitrou
    Copy link
    Member Author

    pitrou commented Nov 23, 2013

    Redoing (indentation issue).

    @vstinner
    Copy link
    Member

    utime_win.patch looks good to me.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 23, 2013

    New changeset 6a9e262c5423 by Antoine Pitrou in branch 'default':
    Issue bpo-19727: os.utime(..., None) is now potentially more precise under Windows.
    http://hg.python.org/cpython/rev/6a9e262c5423

    @pitrou pitrou closed this as completed Nov 23, 2013
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants