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


Groups > comp.lang.python > #81967

Re: time.monotonic() roll over

Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.075
X-Spam-Evidence '*H*': 0.85; '*S*': 0.00; 'caller': 0.09; 'measure': 0.09; 'run,': 0.09; 'subject:skip:t 10': 0.09; 'thread': 0.14; '60,': 0.16; 'adjusted': 0.16; 'being,': 0.16; 'duration,': 0.16; 'operation,': 0.16; 'paused': 0.16; 'repeatedly.': 0.16; 'resumed': 0.16; 'seconds.': 0.16; 'suspend': 0.16; 'thread,': 0.16; 'applies': 0.16; 'wrote:': 0.18; 'normally': 0.19; 'machine': 0.22; 'header:User-Agent:1': 0.23; 'fraction': 0.24; 'hours,': 0.24; 'issue,': 0.24; 'necessary.': 0.24; 'passes': 0.24; 'processor': 0.24; "shouldn't": 0.24; 'pass': 0.26; 'world,': 0.26; 'header:In-Reply-To:1': 0.27; 'external': 0.29; 'absolute': 0.30; 'returned': 0.30; 'specified': 0.30; 'program,': 0.31; 'code': 0.31; 'clock': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'another': 0.32; 'linux': 0.33; 'running': 0.33; 'checking': 0.33; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'adjust': 0.36; 'complete.': 0.36; 'minutes,': 0.36; 'possible': 0.36; 'should': 0.36; 'seconds': 0.37; 'virtual': 0.37; 'so,': 0.37; 'being': 0.38; 'expected': 0.38; 'server': 0.38; 'e.g.': 0.38; 'process,': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'major': 0.40; 'release': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'catch': 0.60; 'continued': 0.60; 'event.': 0.60; 'most': 0.60; 'more': 0.64; 'forward': 0.65; 'finish': 0.65; 'hours': 0.66; 'due': 0.66; 'received:74.208': 0.68; 'hour': 0.70; 'savings': 0.81; 'conservative': 0.84; 'forward,': 0.84; 'soonest': 0.84; 'subject:over': 0.84; 'suspended,': 0.84; 'continue.': 0.91; 'shell,': 0.91; 'suspended': 0.91; 'suspended.': 0.91
Date Thu, 04 Dec 2014 20:21:05 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: time.monotonic() roll over
References <54807cfd$0$2311$426a74cc@news.free.fr> <87vblr8lcw.fsf@elektro.pacujo.net> <mailman.16564.1417709156.18130.python-list@python.org> <87r3wf8jy8.fsf@elektro.pacujo.net> <mailman.16566.1417710430.18130.python-list@python.org> <87ppbzp9qq.fsf@elektro.pacujo.net> <5480fea7$0$12992$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <5480fea7$0$12992$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:aYZYUpeeTsIU3cOM9Sd2sLRAWXKEGwuV3pUS+siX+ty Njop6UjtvcGIqtFIgT9eZpbvrSFvvVLAN52B8h4ZXtpj8F7vv3 2x1h76aBjufBW3pj7ewuwTnuhHmnJRGY7ANDaiT2BRfraEZXxF Jecg3XSFV07qtkIMiFZV66p5JhAOp9wsHmm34Rr2YO4XlClDhF m58lBj0MH31KwKQAhcnL/n/OejmSKa07R0MZookqwvNjt0S7c4 YN3flRrbDqro+vUfRHg5Xh015vPq67Oj6acDLib3rGFL94uA1u dPPcJtgHFvCofaa6m7UJXMtcfSUvdVaI6JSFhaIucWWWe9/9H2 KcVWs9IBXD4HFwyJjfbw=
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16602.1417742485.18130.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417742485 news.xs4all.nl 2857 [2001:888:2000:d::a6]:60624
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:81967

Show key headers only | View raw


On 12/04/2014 07:39 PM, Steven D'Aprano wrote:
> Marko Rauhamaa wrote:
>
>> So, if I call
>>
>> time.sleep(86400)
>>
>> and the program is suspended for 24 hours, should time.sleep() return
>> right after it is resumed or after another 24 hours?
>
> If the program is suspended, then no time should pass for that program.
> Since sleep() is given in terms of a duration, not an absolute time ("sleep
> until now + 24 hours"), if no time passes for that program, sleep() should
> sleep for 24 hours *after the program resumes*.
>
> Unfortunately a lot of systems get that wrong. E.g. I just ran "sleep 30"
> from my Linux shell, immediately paused it using Ctrl-Z, waited a couple of
> minutes, and used fg to continue. It returned immediately.
>
> Why is this behaviour wrong?
>
> Consider why people might call sleep. They're normally calling it to wait
> for something else to complete. Often that something else is an external
> process ("wait a few seconds to let the hard drive finish syncing, wait for
> the web server to get less busy, wait for the user to catch up...") but it
> might be another thread in the same process. If the process is suspended,
> that other thread won't get to run, and so even though time on the outside
> has continued to move forward, from the perspective of the process, it
> hasn't.
>
> The same applies even more so if the process is running in a virtual machine
> which has just been suspended.
>
> The same applies if the system clock is adjusted mid-sleep. If I call sleep
> 60, then immediately adjust the clock forward an hour (say, due to a
> daylight savings adjustment), that shouldn't cause sleep to return. It
> should still suspend for 60 seconds.

And I say you have it exactly backwards.  People should NOT call sleep() 
to measure something, they should only call it to release the processor 
for "up to" a specified time.  That time should normally be a major 
fraction of the time that some external event is expected to take.  Then 
the code should check the external event and sleep some more if necessary.

If efficiency were not an issue, the code would just do a busy loop, 
checking the external condition repeatedly.

Since the OS has no way of knowing whether the thing being waited for is 
a thread, another process, a human being, a network operation, or the 
end of the world, the interpretation of sleep needs to be the most 
conservative one.  There are many ways of suspending a process, and some 
of them will also suspend the external event.  Since the OS cannot know 
which case is significant, it has to return control to the caller at the 
soonest of the many possible interpretations.


-- 
DaveA

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