Behaviour of time.sleep with negative arg

Colin Brown cbrown at metservice.com
Mon Mar 15 14:09:37 EST 2004


"Andrew Bennetts" <andrew-pythonlist at puzzling.org> wrote in message
news:mailman.0.1079317970.12241.python-list at python.org...
> On Sun, Mar 14, 2004 at 03:19:53PM -0600, Jeff Epler wrote:
> > On Mon, Mar 15, 2004 at 08:43:51AM +1300, Colin Brown wrote:
> [...]
> > >     2.    A common usage of sleep is with the difference of two
values. If
> > > it raises an exception on negative numbers then when one takes the
> > > difference of say a timestamp and current-time (real-values), to be
safe you
> > > would need to put the difference in a temporary variable, check that
for
> > > negative and only sleep for positive values - not very elegant.
> >
> > def unsurprising_sleep(d):
> >     if d < 0: return
> >     time.sleep(d)
>
> Or even just:
>
> time.sleep(max(d, 0))
>
> -Andrew.
>
>

Agreed, This is what had I ended up coding, almost acceptable ;-)

Colin






More information about the Python-list mailing list