[New-bugs-announce] [issue12459] time.sleep(-1.0) behaviour

Ulrich Eckhardt report at bugs.python.org
Fri Jul 1 08:45:50 CEST 2011


New submission from Ulrich Eckhardt <eckhardt at satorlaser.com>:

For reference, see the thread on the users' mailinglist/newsgroup from 2011-06-29 "how to call a function for evry 10 seconds" and the thread on the developers' mailinglist from 2011-06-30 "time.sleep(-1) behaviour".

The problem is how negative arguments to time.sleep() are handled. Python 2.x (tested 2.5 and 2.7) implementations on MS Windows seems to have a 32-bit underflow while converting the given argument to the DWORD that is passed to win32's Sleep() function. This causes a small negative value to sleep for a long time.

On Linux, using Python 2.6, you get an IOError instead. While an error is better than blocking effectively forever, the use of an IOError to signal the wrong argument is at least confusing. I guess it is an artifact of the implementation, but that shouldn't be visible prominently.

IMHH, both versions should raise a ValueError to signal invalid arguments. However, there was also the suggestion to simply treat negative values as zero, after all time.sleep() is already documented to possibly sleep longer than specified.

----------
messages: 139548
nosy: eckhardt
priority: normal
severity: normal
status: open
title: time.sleep(-1.0) behaviour
type: behavior

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12459>
_______________________________________


More information about the New-bugs-announce mailing list