# Change of behaviour for sleep(0) in 1.9

**URL:** <https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373>\
**Category:** Ruby\
**Created:** [March 31, 2009, 5:04pm UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373 "2009-03-31T17:04:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [March 31, 2009, 5:04pm UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373/1 "2009-03-31T17:04:30Z")

</div>

Hi,

Just thought I’d share this to save anyone else the bafflement it caused  
me.

In ruby 1.8.x and jruby, sleep(0) means do not sleep at all. In 1.9,  
it appears to mean sleep forever.

In both cases, sleep with no arguments means sleep forever.

Perhaps differing interpretations of this ambiguous documentation from  
ri?

“Zero arguments causes sleep to sleep forever.”

Regards,  
Sean

---

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [March 31, 2009, 7:41pm UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373/2 "2009-03-31T19:41:57Z")

</div>

El Martes 31 Marzo 2009, Sean O’Halpin  
escribió:\> Hi,

> Just thought I’d share this to save anyone else the bafflement it caused  
> me.
> 
> In ruby 1.8.x and jruby, sleep(0) means do not sleep at all. In 1.9,  
> it appears to mean sleep forever.

I’ve tested it in Ruby 1.9.1 and sleep(0) means do not sleep at all.

> Perhaps differing interpretations of this ambiguous documentation from ri?
> 
> “Zero arguments causes sleep to sleep forever.”

This must be a doc bug.

---

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [April 1, 2009, 12:55am UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373/3 "2009-04-01T00:55:07Z")

</div>

On Tue, Mar 31, 2009 at 6:41 PM, Iñaki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> El Martes 31 Marzo 2009, Sean O’Halpin escribió:
> 
> > Hi,
> > 
> > Just thought I’d share this to save anyone else the bafflement it caused  
> > me.
> > 
> > In ruby 1.8.x and jruby, sleep(0) means do not sleep at all. In 1.9,  
> > it appears to mean sleep forever.
> 
> I’ve tested it in Ruby 1.9.1 and sleep(0) means do not sleep at all.

Hmmm. Just tested on Ubuntu 8.04 and sleep(0) works as expected in  
all versions (i.e. it doesn’t wait). However, this is what I get on  
Mac OS X 10.4:

$ multiruby -rtimeout -e ‘Timeout::timeout(2) { sleep(0) }’

[snip working versions]

VERSION = v1\_9\_1\_0  
CMD = ~/.multiruby/install/v1\_9\_1\_0/bin/ruby -rtimeout -e  
Timeout::timeout(2) { sleep(0) }

-e:1:in `sleep': execution expired (Timeout::Error) from -e:1:in `block in ’  
from -e:1:in `’

RESULT = 256

TOTAL RESULT = 1 failures out of 5

Passed: jruby-1.2.0RC2, jruby-1.1.6, v1\_8\_6\_110, 1.8.7-p72  
Failed: v1\_9\_1\_0  
$ uname -a  
Darwin xxxx 8.11.1 Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28  
PDT 2007; root:xnu-792.25.20~1/RELEASE\_I386 i386 i386

I guess I should file a bug report.

Regards,  
Sean

---

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [April 1, 2009, 5:18am UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373/4 "2009-04-01T05:18:17Z")

</div>

Hi,

In message “Re: Change of behaviour for sleep(0) in 1.9”  
on Wed, 1 Apr 2009 00:02:20 +0900, “Sean O’Halpin”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|Perhaps differing interpretations of this ambiguous documentation from ri?  
|“Zero arguments causes sleep to sleep forever.”

“Zero arguments” means “sleep”, not “sleep(0)”. Disambiguation welcome.

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [April 1, 2009, 6:03am UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373/5 "2009-04-01T06:03:53Z")

</div>

On Mar 31, 2009, at 11:17 PM, Yukihiro M. wrote:

> “Zero arguments” means “sleep”, not “sleep(0)”. Disambiguation  
> welcome.
> 
> ```
> matz.
> 
> ```

“Called without an argument, sleep() will sleep forever.”

The fastri output colors the first “sleep” as a Ruby item and leaves  
the second “sleep” as a Human item. It also doesn’t use the empty  
parentheses, but they certainly help in email.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [April 1, 2009, 6:17am UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373/6 "2009-04-01T06:17:54Z")

</div>

Hi,

In message “Re: Change of behaviour for sleep(0) in 1.9”  
on Wed, 1 Apr 2009 13:02:58 +0900, Rob B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|“Called without an argument, sleep() will sleep forever.”

That sounds better. Thank you.

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [April 1, 2009, 3:51pm UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373/7 "2009-04-01T15:51:59Z")

</div>

2009/4/1 Sean O’Halpin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Timeout::timeout(2) { sleep(0) }  
> Failed: v1\_9\_1\_0  
> Hm, works for me:

15:49:23 bas$ allruby -e ‘puts Time.now; sleep 0; puts Time.now’  
CYGWIN\_NT-5.1 padrklemme1 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin  
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]  
Wed Apr 01 15:49:24 +0200 2009  
Wed Apr 01 15:49:24 +0200 2009  
ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-cygwin]  
2009-04-01 15:49:25 +0100  
2009-04-01 15:49:25 +0100  
15:49:25 bas$

Cheers

robert

---

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [April 1, 2009, 7:17pm UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373/8 "2009-04-01T19:17:45Z")

</div>

Sean O’halpin wrote:

> On Wed, Apr 1, 2009 at 2:50 PM, Robert K.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hm, works for me:
> > 
> > 15:49:23 bas$ allruby -e ‘puts Time.now; sleep 0; puts Time.now’  
> > CYGWIN\_NT-5.1 padrklemme1 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin
> 
> Looks like a Mac OSX thing then. I’ve filed a bug report. Is there  
> anyone else out there with ruby 1.9 on OSX (10.4 or 10.5) who can  
> confirm that this is a problem?

$ uname -a  
Darwin Machine.local 8.11.0 Darwin Kernel Version 8.11.0: Wed Oct 10  
18:26:00 PDT 2007; root:xnu-792.24.17~1/RELEASE\_PPC Power Macintosh  
powerpc

$ ruby-1.9 -v  
ruby 1.9.1p0 (2009-01-30 revision 21907) [powerpc-darwin8.11.0]

$ ruby-1.9 -r Timeout -e ‘Timeout.timeout(1) {sleep(0)}’  
-e:1:in `sleep': execution expired (Timeout::Error) from -e:1:in `block in ’  
from -e:1:in `’  
$

Seems to be a problem here, too.

---

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [April 1, 2009, 6:26pm UTC](https://www.ruby-forum.com/t/change-of-behaviour-for-sleep-0-in-1-9/164373/9 "2009-04-01T18:26:28Z")

</div>

On Wed, Apr 1, 2009 at 2:50 PM, Robert K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hm, works for me:
> 
> 15:49:23 bas$ allruby -e ‘puts Time.now; sleep 0; puts Time.now’  
> CYGWIN\_NT-5.1 padrklemme1 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin

Looks like a Mac OSX thing then. I’ve filed a bug report. Is there  
anyone else out there with ruby 1.9 on OSX (10.4 or 10.5) who can  
confirm that this is a problem?
