time.monotonic() roll over

Chris Angelico rosuav at gmail.com
Thu Dec 4 11:12:48 EST 2014


On Fri, Dec 5, 2014 at 3:05 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Dec 4, 2014 8:56 AM, "Marko Rauhamaa" <marko at pacujo.net> wrote:
>>
>> "ast" <nomail at invalid.com>:
>>
>> > Does any body know when time.monotonic() rolls over ?
>>
>> Never, according to the documentation you linked.
>>
>> Admittedly, the documentation confuses the reader by chatting about some
>> irrelevant internal Windows details.
>
> Not entirely irrelevant. The implication is that if you go more than 49 days
> without calling the function on old Windows systems, rollovers could be
> missed, which is good to know about. The result would still be monotonic,
> but it wouldn't accurately reflect the time elapsed.

I don't know for sure about the newer Windowses, but I believe they
use a 64-bit counter instead of the 32-bit one used in previous
versions, so even if they do roll over, there'll be a much MUCH longer
time scale involved. Even if it stores time in nanoseconds, a 64-bit
counter would allow for hundreds of years between rollovers, which is
reasonably safe - much better than the month-and-a-bit of older ones,
which is shorter than quite a lot of my programs' uptimes. Hence the
lack of information about them; you don't have to worry. (Likewise on
Unix-derived systems, I believe, and for the same reason.)

ChrisA



More information about the Python-list mailing list