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

Add time.monotonic() function #58054

Closed
vstinner opened this issue Jan 24, 2012 · 11 comments
Closed

Add time.monotonic() function #58054

vstinner opened this issue Jan 24, 2012 · 11 comments
Labels
type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

BPO 13846
Nosy @terryjreedy, @abalkin, @pitrou, @vstinner, @giampaolo, @ned-deily, @merwok, @bitdancer
Files
  • monotonic.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-02-07.22:30:30.812>
    created_at = <Date 2012-01-24.00:22:29.067>
    labels = ['type-feature']
    title = 'Add time.monotonic() function'
    updated_at = <Date 2012-02-23.23:11:18.533>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2012-02-23.23:11:18.533>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-02-07.22:30:30.812>
    closer = 'vstinner'
    components = []
    creation = <Date 2012-01-24.00:22:29.067>
    creator = 'vstinner'
    dependencies = []
    files = ['24307']
    hgrepos = []
    issue_num = 13846
    keywords = ['patch']
    message_count = 11.0
    messages = ['151868', '152138', '152280', '152505', '152506', '152514', '152816', '152860', '153774', '154096', '154097']
    nosy_count = 10.0
    nosy_names = ['terry.reedy', 'belopolsky', 'pitrou', 'vstinner', 'giampaolo.rodola', 'ned.deily', 'eric.araujo', 'r.david.murray', 'rosslagerwall', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue13846'
    versions = ['Python 3.3']

    @vstinner
    Copy link
    Member Author

    After time.wallclock() (issue bpo-10278), let add a time.monotomic() function. It is similar to time.wallclock() (try to get the most accurate clock) but is not available if the system doesn't provide a monotonic clock. It may also fail at runtime if Python cannot find a monotonic clock, whereas time.clock() and time.wallclock() fallback on a wallclock which may go backward on NTP adjust.

    The documentation of the patch should be improved :-)

    wallclock() tests may be simplified or dropped because they may fail on NTP adjust.

    @terryjreedy
    Copy link
    Member

    Do we actually yet another function, or could this be covered by adding a parameter such as monotonic=False, perhaps to wallclock().

    @terryjreedy terryjreedy added the type-feature A feature request or enhancement label Jan 27, 2012
    @vstinner
    Copy link
    Member Author

    Do we actually yet another function, or could this be covered by adding a parameter such as monotonic=False, perhaps to wallclock().

    A monotonic is a different clock, it would be surprising that an
    argument uses another clock.

    @merwok
    Copy link
    Member

    merwok commented Feb 3, 2012

    I don’t understand why this new function would be useful. Time-related modules in Python are already complicated.

    @bitdancer
    Copy link
    Member

    If you are trying to time something (an interval), having the time go backward can really screw up your data. And that *will* happen on a system that is running NTP (or even just resets its time). monotonic clocks were introduced at the OS level for a reason, and it seems reasonable for Python to expose them (when the are available) like it does other system resources.

    @merwok
    Copy link
    Member

    merwok commented Feb 3, 2012

    Thanks, now I see the usefulness.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 7, 2012

    New changeset 376ce937823c by Victor Stinner in branch 'default':
    Issue bpo-13846: Add time.monotonic(), monotonic clock.
    http://hg.python.org/cpython/rev/376ce937823c

    @vstinner vstinner closed this as completed Feb 7, 2012
    @merwok
    Copy link
    Member

    merwok commented Feb 8, 2012

    Victor, I think the doc doesn’t say why the function is useful for people like me who don’t already know it. David’s explanation could be reused.

    @pitrou
    Copy link
    Member

    pitrou commented Feb 20, 2012

    Boost has a monotonic time implementation (steady_clock) for OS X:
    http://svn.boost.org/svn/boost/trunk/boost/chrono/detail/inlined/mac/chrono.hpp

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 23, 2012

    New changeset 50b1f2d07011 by Victor Stinner in branch 'default':
    Issue bpo-13846: Enhance time.monotonic() documentation
    http://hg.python.org/cpython/rev/50b1f2d07011

    @vstinner
    Copy link
    Member Author

    Boost has a monotonic time implementation (steady_clock) for OS X

    I opened a new issue for Mac OS X: bpo-14104.

    --

    @Éric: I enhanced the doc. Feel free to complete or rewrite it if you have better information about such clocks.

    @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
    type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants