# Sleep function duration changes when system clock is modifie

**URL:** <https://www.ruby-forum.com/t/sleep-function-duration-changes-when-system-clock-is-modifie/85339>\
**Category:** Rails\
**Created:** [February 12, 2007, 8:46pm UTC](https://www.ruby-forum.com/t/sleep-function-duration-changes-when-system-clock-is-modifie/85339 "2007-02-12T20:46:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jan](https://www.ruby-forum.com/u/jan)\
**Post date:** [February 12, 2007, 8:46pm UTC](https://www.ruby-forum.com/t/sleep-function-duration-changes-when-system-clock-is-modifie/85339/1 "2007-02-12T20:46:01Z")

</div>

My problem is related to the behaviour of sleep function. If, during  
the execution of sleep function, I change the system clock of my PC,  
sleep function will not recover from sleeping when it should.

Example:

My controller:

def index  
logger.info “Start sleeping at:”+Time.now.to\_s  
sleep 5  
logger.info “Sleeping finished at:”+Time.now.to\_s  
end

Everythink works well if I don’t change the system time during the  
execution of sleep function.  
However, if during the execution of sleep function I shift the system  
time, let’s say 1 minute back, I’ll need to wait 1 minute and 5  
seconds until the sleep function finishes.

I’d need to force sleep function to sleep always 5 seconds, even if  
the system time changes during the call of the sleep function.

If I try somethink similar in pure ruby (no rails), everythink works  
as expected, I can change system time without any consequences to the  
behaviour of sleep function.

I am using Rails 1.2.1 under WinXP.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![jan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jan](https://www.ruby-forum.com/u/jan)\
**Post date:** [February 12, 2007, 9:10pm UTC](https://www.ruby-forum.com/t/sleep-function-duration-changes-when-system-clock-is-modifie/85339/2 "2007-02-12T21:10:24Z")

</div>

Jan wrote:

> My problem is related to the behaviour of sleep function. If, during  
> the execution of sleep function, I change the system clock of my PC,  
> sleep function will not recover from sleeping when it should.

While odd, why is this really a problem? You shouldnt be manually  
changing the system clock very often.

---

<div class="post-metadata">

**Author:** ![jan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jan](https://www.ruby-forum.com/u/jan)\
**Post date:** [February 12, 2007, 10:00pm UTC](https://www.ruby-forum.com/t/sleep-function-duration-changes-when-system-clock-is-modifie/85339/3 "2007-02-12T22:00:13Z")

</div>

The server application will be running on customer’s PC and the sleep  
function is used in a background thread. In these conditions, the  
manual change of system clock may happen and I would’nt like if this  
freezed the background thread.

---

<div class="post-metadata">

**Author:** ![jan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jan](https://www.ruby-forum.com/u/jan)\
**Post date:** [November 6, 2007, 3:46pm UTC](https://www.ruby-forum.com/t/sleep-function-duration-changes-when-system-clock-is-modifie/85339/4 "2007-11-06T15:46:08Z")

</div>

Bump…I am also experiencing this problem with Fedora Core 6 & 7

[http://www.ruby-forum.com/topic/123178#new](http://www.ruby-forum.com/topic/123178#new)  
[http://www.ruby-forum.com/topic/130593#new](http://www.ruby-forum.com/topic/130593#new)
