Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82006

Re: time.monotonic() roll over

References (5 earlier) <87ppbzp9qq.fsf@elektro.pacujo.net> <CALwzidn=g4+Rm0SJtSoXyA_5-QtgPBCNYOQ-kY9FYNaX__dJmw@mail.gmail.com> <87wq6788op.fsf@gmail.com> <mailman.16591.1417731511.18130.python-list@python.org> <87r3wfnih0.fsf@elektro.pacujo.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-12-05 10:04 -0700
Subject Re: time.monotonic() roll over
Newsgroups comp.lang.python
Message-ID <mailman.16628.1417799143.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Thu, Dec 4, 2014 at 3:44 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
>
> Ian Kelly <ian.g.kelly@gmail.com>:
>
> > It's not clear to me whether those cases are relevant to the rollover
> > concern anyway. I wouldn't be shocked if the GetTickCount() function
> > simply stopped increasing while the system is suspended, since after
> > all it's not "ticking" during that time.
>
> So, what's the semantics of time.sleep(), select.select() et al wrt
> process or machine suspension?

Rather than continue to speculate, I just tested this. I ran the following
script in a Windows 7 VM and paused the VM for part of the duration of the
sleep call. I unpaused well before the sleep call would normally have ended.

>>> import time
>>> def test():
...   t1 = time.time()
...   m1 = time.monotonic()
...   time.sleep(60)
...   t2 = time.time()
...   m2 = time.monotonic()
...   return t2 - t1, m2 - m1
...
>>> test()
(84.92642459869386, 60.002399999999994)

As you can see, the sleep call and the monotonic time elapsed both appear
to exclude the period when the VM was paused.

Then I tried the same with a MacBook and putting the system to sleep
instead of pausing a VM:

>>> test()
(59.889225006103516, 60.00102640298428)

Reducing the sleep time to 10 seconds and suspending the process with
Ctrl-Z produces a similar result on the MacBook:
(10.000508069992065, 10.000266332994215)

But the story is different in Linux. Here's what I got with the same Ctrl-Z
test:
(16.000478506088257, 16.000478034024127)

I think the relative roundness of those numbers is just coincidence. I
tried a second time and got:
(12.613622903823853, 12.613622067990946)

So it seems that it can go either way depending on the OS and perhaps the
mechanism of suspension.

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

time.monotonic() roll over "ast" <nomail@invalid.com> - 2014-12-04 16:25 +0100
  Re: time.monotonic() roll over Marko Rauhamaa <marko@pacujo.net> - 2014-12-04 17:50 +0200
    Re: time.monotonic() roll over Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-04 09:05 -0700
      Re: time.monotonic() roll over Marko Rauhamaa <marko@pacujo.net> - 2014-12-04 18:21 +0200
        Re: time.monotonic() roll over Chris Angelico <rosuav@gmail.com> - 2014-12-05 03:27 +1100
          Re: time.monotonic() roll over Marko Rauhamaa <marko@pacujo.net> - 2014-12-04 20:09 +0200
            Re: time.monotonic() roll over Chris Angelico <rosuav@gmail.com> - 2014-12-05 05:29 +1100
              Re: time.monotonic() roll over Marko Rauhamaa <marko@pacujo.net> - 2014-12-04 20:44 +0200
                Re: time.monotonic() roll over Chris Angelico <rosuav@gmail.com> - 2014-12-05 07:02 +1100
            Re: time.monotonic() roll over Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-04 12:29 -0700
            Re: time.monotonic() roll over Akira Li <4kir4.1i@gmail.com> - 2014-12-04 23:24 +0300
            Re: time.monotonic() roll over Chris Angelico <rosuav@gmail.com> - 2014-12-05 07:33 +1100
              Re: time.monotonic() roll over Marko Rauhamaa <marko@pacujo.net> - 2014-12-04 22:51 +0200
            Re: time.monotonic() roll over Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-04 15:17 -0700
              Re: time.monotonic() roll over Marko Rauhamaa <marko@pacujo.net> - 2014-12-05 00:44 +0200
                Re: time.monotonic() roll over Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-05 10:04 -0700
                Re: time.monotonic() roll over Marko Rauhamaa <marko@pacujo.net> - 2014-12-05 20:48 +0200
            Re: time.monotonic() roll over Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 11:39 +1100
              Re: time.monotonic() roll over Dave Angel <davea@davea.name> - 2014-12-04 20:21 -0500
                Re: time.monotonic() roll over Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 13:54 +1100
                Re: time.monotonic() roll over Dave Angel <davea@davea.name> - 2014-12-05 00:29 -0500
                Re: time.monotonic() roll over Lele Gaifax <lele@metapensiero.it> - 2014-12-05 08:56 +0100
                Re: time.monotonic() roll over Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 21:09 +1100
                Re: time.monotonic() roll over Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-12-05 12:12 -0500
              Re: time.monotonic() roll over Marko Rauhamaa <marko@pacujo.net> - 2014-12-05 08:17 +0200
                Re: time.monotonic() roll over Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-12-05 12:31 -0500
              Re: time.monotonic() roll over Akira Li <4kir4.1i@gmail.com> - 2014-12-05 12:48 +0300
    Re: time.monotonic() roll over Chris Angelico <rosuav@gmail.com> - 2014-12-05 03:12 +1100
    Re: time.monotonic() roll over random832@fastmail.us - 2014-12-04 11:51 -0500
  Re: time.monotonic() roll over Nobody <nobody@nowhere.invalid> - 2014-12-05 00:54 +0000

csiph-web