Skip to content

os.utimensat() and os.futimes() should accept (sec, nsec), drop os.futimens() #58172

Closed

Description

@vstinner
BPO 13964
Nosy @ncoghlan, @vstinner, @larryhastings
Files
  • pytime.patch
  • utime.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 2012-03-13.13:05:15.803>
    created_at = <Date 2012-02-08.01:19:53.483>
    labels = ['library']
    title = 'os.utimensat() and os.futimes() should accept (sec, nsec), drop os.futimens()'
    updated_at = <Date 2012-03-13.13:05:15.802>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2012-03-13.13:05:15.802>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-03-13.13:05:15.803>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2012-02-08.01:19:53.483>
    creator = 'vstinner'
    dependencies = []
    files = ['24586', '24725']
    hgrepos = []
    issue_num = 13964
    keywords = ['patch']
    message_count = 19.0
    messages = ['152825', '152828', '152829', '152830', '152831', '152832', '152833', '152834', '152919', '152920', '153825', '154805', '154812', '154813', '154814', '154860', '154862', '155136', '155606']
    nosy_count = 6.0
    nosy_names = ['ncoghlan', 'vstinner', 'larry', 'Arfrever', 'rosslagerwall', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue13964'
    versions = ['Python 3.3']

    Activity

    1. vstinner commented on Feb 8, 2012

      @vstinner
      MemberAuthor

      Python 3.3 has 4 new functions to set the access and modification time of a file (only os.utime() was already present in Python 3.2). New functions taking timestamp with a nanonsecond resolution use a tuple of int because the float type doesn't support nanosecond resolution. Thanks to the PEP-410, we can simplify the API to use a simple number (int, float or Decimal) instead of a tuple of 2 integers.

      Current API:

      • futimes(fd[, (atime, mtime)]): 1 argument for timestamps

      • lutimes(path[, (atime, mtime)]): 1 argument for timestamps

      • utime(path[, (atime, mtime)]): 1 argument for timestamps

      • futimens(fd[, (atime_sec, atime_nsec), (mtime_sec, mtime_nsec)]): 2 arguments for timestamps

      • utimensat(dirfd, path[, atime=(atime_sec, atime_nsec), mtime=(mtime_sec, mtime_nsec), flags=0]): 2 arguments for timestamps

      I propose to:

      • support Decimal type in all functions: avoid conversion to float to not lose precision
      • remove os.futimens(): os.futimes() does already use futimens() if the function is present (and Decimal can be used to get nanosecond resolution)
      • change os.utimensat() API to: os.utimensat(dirfd, path[, (atime, mtime), flags=0])
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Feb 8, 2012
    3. python-dev commented on Feb 8, 2012

      python-devmannequin
      Mannequin

      New changeset d297f9b10c64 by Victor Stinner in branch 'default':
      Issue bpo-13964: Write tests for new os.*utime*() functions
      http://hg.python.org/cpython/rev/d297f9b10c64

    4. vstinner commented on Feb 8, 2012

      @vstinner
      MemberAuthor

      Current API:

      Oh, I forgot:

      • futimesat(dirfd, path[, (atime, mtime)])

      This API looks fine.

    5. python-dev commented on Feb 8, 2012

      python-devmannequin
      Mannequin

      New changeset c6e9c4d18b36 by Victor Stinner in branch 'default':
      Issue bpo-13964: Test also os.futimesat()
      http://hg.python.org/cpython/rev/c6e9c4d18b36

    6. Arfrever commented on Feb 8, 2012

      Arfrevermannequin
      Mannequin

      I suggest to support the following functions:
      futimes(fd, (atime, mtime), flags=0)
      utimes(path, (atime, mtime), flags=0)
      utimesat(dirfd, path, (atime, mtime), flags=0)

      And deprecate other functions already present in 3.2.
      flags argument of utimes*() would specify e.g. if symlinks should be dereferenced, so lutime*() wouldn't be needed.

    7. python-dev commented on Feb 8, 2012

      python-devmannequin
      Mannequin

      New changeset 478fb4869c99 by Victor Stinner in branch 'default':
      Issue bpo-13964: Split os.*utime*() subsecond tests into multiple tests to help
      http://hg.python.org/cpython/rev/478fb4869c99

    8. python-dev commented on Feb 8, 2012

      python-devmannequin
      Mannequin

      New changeset 58bd6a58365d by Victor Stinner in branch 'default':
      Issue bpo-13964: Skip os.*utime*() tests if os.stat() doesn't support timestamp
      http://hg.python.org/cpython/rev/58bd6a58365d

    9. vstinner commented on Feb 8, 2012

      @vstinner
      MemberAuthor

      New changeset 478fb4869c99 by Victor Stinner in branch 'default':
      Issue bpo-13964: Split os.*utime*() subsecond tests into multiple tests...

      Oops, I also commited my change on extract_time() by mistake. But it is not completly a mistake: it was the goal of my patch serie :-)

      This commit changes two things on extract_time().

      • always use nanoseconds: if we need microseconds, divide by 1000
      • use (long)(fmod()*1e9) to get nanoseconds instead of the previous code, I'm not sure that this change is correct
    10. vstinner commented on Feb 9, 2012

      @vstinner
      MemberAuthor

      signal.sigtimedwait() API should also be changed from:
      sigtimedwait(sigset, (timeout_sec, timeout_nsec))
      to:
      sigtimedwait(sigset, timeout)

      where timeout can be an int, float or decimal.Decimal. The function was introduced in Python 3.3, so its API can be changed.

    11. Arfrever commented on Feb 9, 2012

      Arfrevermannequin
      Mannequin

      Updated version of my suggestion:
      os.futime(fd, (atime, mtime))
      os.utime(path, (atime, mtime), flags=0)
      os.utimeat(dirfd, path, (atime, mtime), flags=0)

      atime and mtime could be int, float, decimal.Decimal or None.
      All other os.*utime*() functions were introduced in 3.3, so they would be removed.
      flags argument of os.utime() and os.utimeat() could be 0 or os.SYMLINK_NOFOLLOW.

    12. vstinner commented on Feb 21, 2012

      @vstinner
      MemberAuthor

      Here is a first step: add _PyTime_ObjectToTimespec() to pytime.h and use it for signal.sigtimedwait().

      signal.sigtimedwait(sigwait, (timeout_sec, timeout_nsec)) becomes signal.sigtimedwait(sigwait, timeout).

      I chose pytime.h instead of timefuncs.h because I plan to use _PyTime_ObjectToTimespec() in the posix module. I don't want to have a copy of this function in each module: timefuncs.h requires to compile the module with _time.c.

    13. python-dev commented on Mar 2, 2012

      python-devmannequin
      Mannequin

      New changeset 67d9595a833c by Victor Stinner in branch 'default':
      Issue bpo-13964: signal.sigtimedwait() timeout is now a float instead of a tuple
      http://hg.python.org/cpython/rev/67d9595a833c

    14. vstinner commented on Mar 3, 2012

      @vstinner
      MemberAuthor

      I created the issue bpo-14180 to prepare a refactoring before changing os.*utime*() functions.

    15. larryhastings commented on Mar 3, 2012

      @larryhastings
      Contributor

      Um, doesn't the rejection of PEP-410 mean this should be discontinued?

    16. vstinner commented on Mar 3, 2012

      @vstinner
      MemberAuthor

      Um, doesn't the rejection of PEP-410 mean this should be discontinued?

      There is an issue in shutil.copystat() on copying the timestamp: in this specific use case, we need nanosecond resolution.

      Guido proposes (in a private mail thread) to add st_atime_ns, st_mtime_ns, st_ctime_ns fields to os.stat() and make os.*utime*() functions accept a (sec, nsec) tuple. It would still be possible to pass a number or seconds as an int or float.

      I plan to implement this request.

    17. changed the title [-]os.utimensat() and os.futimes() should accept Decimal, drop os.futimens()[/-] [+]os.utimensat() and os.futimes() should accept (sec, nsec), drop os.futimens()[/+] on Mar 3, 2012
    18. vstinner commented on Mar 4, 2012

      @vstinner
      MemberAuthor

      utime.patch: ugly draft to add support of (sec, nsec) tuple to os.*utime*() functions.

    19. larryhastings commented on Mar 4, 2012

      @larryhastings
      Contributor

      After Guido rejected 410 and said "let's just do nanoseconds, take it to the bug tracker" I created issue bpo-14127. Your having changed this issue to be the same thing means that at least one of 'em is redundant. Could you engage on that issue, or close it, or something?

    20. larryhastings commented on Mar 8, 2012

      @larryhastings
      Contributor

      I just asked Guido in person, and he says he never intended to suggest accepting a (sec, nsec) tuple. os.*utime* may accept atime and mtime as either float seconds-since-the-epoch, or int nanoseconds-since-the-epoch when passed in using the ns= named parameter.

    21. vstinner commented on Mar 13, 2012

      @vstinner
      MemberAuthor

      This issue is a duplicate of bpo-14127.

    22. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions