time.monotonic() roll over

Marko Rauhamaa marko at pacujo.net
Fri Dec 5 01:17:53 EST 2014


Steven D'Aprano <steve+comp.lang.python at pearwood.info>:

> 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?

I think the #1 thing is to specify the behavior clearly. I'm not seeing
that so it is impossible to say if the GNU coreutils sleep or
time.sleep() does what it was designed to do. I must admit I have
neglected to document that situation in some of my related designs.

Also, I think what is right or wrong depends on the use case. Ideally,
there are facilities to implement the desired semantics.

If a program spends long periods in an induced coma (which is becoming
more and more common nowadays), the whole design of the program is under
quite a bit of strain. What to do with time-based statistics collection?
Should periodic operations catch up with the lost time by repeating in a
tight loop for a zillion times? What to do with "impossible,"
out-of-order event sequences?


Marko



More information about the Python-list mailing list