time.sleep(-1) behaviour
Hi! This is a request for clarification for the thread "how to call a function for evry 10 seconds" from the user mailinglist/newsgroup. The gist is this: 1. On Linux/Python 2.6, time.sleep(-1.0) raises an IOError. 2. On MS Windows/Python 2.5 or 2.7 this sleeps forever. It seems that converting this to a 32-bit integer for Sleep() causes an underflow. Questions: 1. Is the IOError somehow explainable? 2. Is the IOError acceptable or a bug? 3. Is the behaviour under MS Windows acceptable or a bug? 4. Since time.sleep() is documented to possibly sleep a bit longer than specified, someone suggested that the overall sleep time could also be truncated to a minimum of zero, i.e. treating negative values as zero. Greetings! Uli ************************************************************************************** Domino Laser GmbH, Fangdieckstra�e 75a, 22547 Hamburg, Deutschland Gesch�ftsf�hrer: Thorsten F�cking, Amtsgericht Hamburg HR B62 932 ************************************************************************************** Visit our website at http://www.dominolaser.com ************************************************************************************** Diese E-Mail einschlie�lich s�mtlicher Anh�nge ist nur f�r den Adressaten bestimmt und kann vertrauliche Informationen enthalten. Bitte benachrichtigen Sie den Absender umgehend, falls Sie nicht der beabsichtigte Empf�nger sein sollten. Die E-Mail ist in diesem Fall zu l�schen und darf weder gelesen, weitergeleitet, ver�ffentlicht oder anderweitig benutzt werden. E-Mails k�nnen durch Dritte gelesen werden und Viren sowie nichtautorisierte �nderungen enthalten. Domino Laser GmbH ist f�r diese Folgen nicht verantwortlich. **************************************************************************************
On Thu, 30 Jun 2011 21:13:46 +0200, Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> wrote:
1. Is the IOError somehow explainable? 2. Is the IOError acceptable or a bug? 3. Is the behaviour under MS Windows acceptable or a bug? 4. Since time.sleep() is documented to possibly sleep a bit longer than specified, someone suggested that the overall sleep time could also be truncated to a minimum of zero, i.e. treating negative values as zero.
Please file a bug report at bugs.python.org. -- R. David Murray http://www.bitdance.com
On Thursday 30 June 2011, R. David Murray wrote:
Please file a bug report at bugs.python.org.
Filed as bug #12459. Uli ************************************************************************************** Domino Laser GmbH, Fangdieckstraße 75a, 22547 Hamburg, Deutschland Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 ************************************************************************************** Visit our website at http://www.dominolaser.com ************************************************************************************** Diese E-Mail einschließlich sämtlicher Anhänge ist nur für den Adressaten bestimmt und kann vertrauliche Informationen enthalten. Bitte benachrichtigen Sie den Absender umgehend, falls Sie nicht der beabsichtigte Empfänger sein sollten. Die E-Mail ist in diesem Fall zu löschen und darf weder gelesen, weitergeleitet, veröffentlicht oder anderweitig benutzt werden. E-Mails können durch Dritte gelesen werden und Viren sowie nichtautorisierte Änderungen enthalten. Domino Laser GmbH ist für diese Folgen nicht verantwortlich. **************************************************************************************
Le jeudi 30 juin 2011 à 21:13 +0200, Ulrich Eckhardt a écrit :
Hi!
This is a request for clarification for the thread "how to call a function for evry 10 seconds" from the user mailinglist/newsgroup.
The gist is this: 1. On Linux/Python 2.6, time.sleep(-1.0) raises an IOError. 2. On MS Windows/Python 2.5 or 2.7 this sleeps forever. It seems that converting this to a 32-bit integer for Sleep() causes an underflow.
select.select() was changed recently to raise an exception if the timeout is negative to get the same behaviour on all platforms. signal.sigtimedwait() (recently added function) raises also an exception if the timeout is negative. If it's an overflow, Python should raise an OverflowError, or raise another error, but not sleep for 2^32-1 (or 2^64-1 ?) seconds. Victor
On Thu, Jun 30, 2011 at 15:13, Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> wrote:
Hi!
This is a request for clarification for the thread "how to call a function for evry 10 seconds" from the user mailinglist/newsgroup.
The gist is this: 1. On Linux/Python 2.6, time.sleep(-1.0) raises an IOError. 2. On MS Windows/Python 2.5 or 2.7 this sleeps forever. It seems that converting this to a 32-bit integer for Sleep() causes an underflow.
3. Is the behaviour under MS Windows acceptable or a bug?
On the Windows side, Sleep(-1) as "infinite" is correct and documented: http://msdn.microsoft.com/en-us/library/ms686298(v=vs.85).aspx -- Tim Lesher <tlesher@gmail.com>
On Fri, Jul 1, 2011 at 10:17 PM, Tim Lesher <tlesher@gmail.com> wrote:
On Thu, Jun 30, 2011 at 15:13, Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> wrote:
Hi!
This is a request for clarification for the thread "how to call a function for evry 10 seconds" from the user mailinglist/newsgroup.
The gist is this: 1. On Linux/Python 2.6, time.sleep(-1.0) raises an IOError. 2. On MS Windows/Python 2.5 or 2.7 this sleeps forever. It seems that converting this to a 32-bit integer for Sleep() causes an underflow.
3. Is the behaviour under MS Windows acceptable or a bug?
On the Windows side, Sleep(-1) as "infinite" is correct and documented:
http://msdn.microsoft.com/en-us/library/ms686298(v=vs.85).aspx
For Sleep, yes, but the time.sleep() docs [1] are completely silent on the behaviour of negative sleep values at the Python level. Question 3 isn't "Is there something wrong with Sleep()?", it is "Is there something wrong with the way time.sleep() *uses* Sleep()?" My personal preference would be to standardise on ValueError (since the negative sleep value is the real problem), or, failing that, at least raising an exception of some kind. [1] http://docs.python.org/dev/library/time#time.sleep Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
On Fri, Jul 1, 2011 at 08:46, Nick Coghlan <ncoghlan@gmail.com> wrote:
For Sleep, yes, but the time.sleep() docs [1] are completely silent on the behaviour of negative sleep values at the Python level. Question 3 isn't "Is there something wrong with Sleep()?", it is "Is there something wrong with the way time.sleep() *uses* Sleep()?"
That makes sense. Better to be consistent within the time API--I know the different semantics of time.clock() have confused people around here. -- Tim Lesher <tlesher@gmail.com>
Le vendredi 01 juillet 2011 à 08:17 -0400, Tim Lesher a écrit :
On Thu, Jun 30, 2011 at 15:13, Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> wrote:
Hi!
This is a request for clarification for the thread "how to call a function for evry 10 seconds" from the user mailinglist/newsgroup.
The gist is this: 1. On Linux/Python 2.6, time.sleep(-1.0) raises an IOError. 2. On MS Windows/Python 2.5 or 2.7 this sleeps forever. It seems that converting this to a 32-bit integer for Sleep() causes an underflow.
3. Is the behaviour under MS Windows acceptable or a bug?
On the Windows side, Sleep(-1) as "infinite" is correct and documented:
http://msdn.microsoft.com/en-us/library/ms686298(v=vs.85).aspx
I answered on the bug tracker: http://bugs.python.org/issue12459 Victor
participants (5)
-
Nick Coghlan
-
R. David Murray
-
Tim Lesher
-
Ulrich Eckhardt
-
Victor Stinner