Forum: Ruby Strange behaviour with sleep() in a thread...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A7690aa3cc37bb04399041f0049bc21a?d=identicon&s=25 Just Another Victim of the Ambient Morality (Guest)
on 2008-12-24 11:00
(Received via mailing list)
I have a thread created with that does some polling.  I don't
want it to busy wait so I call the sleep method like so:


    ...this should allow me to poll every minute which is good enough
for my
application.  However, I'm finding that calling sleep from a thread in
manner often sleeps for a good deal longer than a minute.  So far, I
find it
sleeping for about 8 or so minutes.  The main thread is blocked in a
    What I'm actually trying to do is implement a simple timer.  I'm
to do something at a certain point in time, like a cron job, without
    Why is sleep behaving so strangely?  Is there a simple way of doing
I'm trying to do?
    Thank you...
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2008-12-27 01:04
>     Why is sleep behaving so strangely?  Is there a simple way of doing
> what
If you're on 1.8.x then your two threads are actually one "real thread"
running two green threads.  One of the green threads [the gets] might be
blocking and not allowing control to return to the other.
Fix (should this be the case): make the one not block, or use 1.9
This topic is locked and can not be replied to.