Sleeping threads don't wake up?

I have the following code:
class Server
    def start_reaper
        @reaper = Thread.new do
            loop do
                sleep 10
                self.clean_workers
                puts "cleaned up"
            end
        end
    end

    # other stuff goes here...
end

server = Server.new
DRb.start_service(nil, server)
server.start_reaper
DRb.thread.join

The problem is that it seems that the loop, well doesn't loop. It
looks like the thread goes to sleep after one iteration and doesn't
wake up based on the number of times "cleaned up" is printed.
Suggestions?

···

--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing & replay tools for Unix
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety. -- Benjamin Franklin

Hi,

require 'drb'

=> true

class Server
def start_reaper
@reaper = Thread.new do

?> loop do
?> sleep 10

puts "looping"
end
end
end
end

=> nil

server = Server.new

=> #<Server:0xb7a9f544>

DRb.start_service(nil, server)

=> #<DRb::lots of rubbish here>>

?> server.start_reaper
=> #<Thread:0xb7a8818c sleep>

DRb.thread.join

looping
looping
looping
looping

It may be output buffering.

Arlen

Hmm... no, it's not output buffering. What OS/ruby ver are you on?
I'm on Linux/1.8.6.

···

On Thu, Feb 28, 2008 at 8:48 PM, Arlen Cuss <celtic@sairyx.org> wrote:

Hi,

>> require 'drb'
=> true

>> class Server
>> def start_reaper
>> @reaper = Thread.new do
?> loop do
?> sleep 10
>> puts "looping"
>> end
>> end
>> end
>> end
=> nil
>> server = Server.new
=> #<Server:0xb7a9f544>

>> DRb.start_service(nil, server)

=> #<DRb::lots of rubbish here>>
>>
?> server.start_reaper
=> #<Thread:0xb7a8818c sleep>
>> DRb.thread.join
looping
looping
looping
looping

It may be output buffering.

Arlen

--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing & replay tools for Unix
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety. -- Benjamin Franklin

Aaron Turner wrote:

>> puts "looping"
=> #<DRb::lots of rubbish here>>

Arlen

Hmm... no, it's not output buffering. What OS/ruby ver are you on?
I'm on Linux/1.8.6.

Before you check the OS, take a look at the code, your version is
calling:
self.clean_workers while Arlens is printing to the screen...

The first place I would look is clean_workers() and ask yourself if it's
logging, throwing, stuck, interrupted, etc..

rdebug would then be your second place to visit

hth

ilan

···

On Thu, Feb 28, 2008 at 8:48 PM, Arlen Cuss <celtic@sairyx.org> wrote:

--
Posted via http://www.ruby-forum.com/\.

Hi,

Hmm... no, it's not output buffering. What OS/ruby ver are you on?

I'm on Linux/1.8.6.

>> celtic@sohma:~$ irb -v
irb 0.9.5(05/04/13)
celtic@sohma:~$ ruby -v
ruby 1.8.6 (2007-06-07 patchlevel 36) [i486-linux]
celtic@sohma:~$

Same, it seems! Ilan's suggestion seems good.

Arlen

Thanks Ilan. That's exactly what was going on. I thought I was
rescuing all errors, but uh, yeah... :slight_smile:

···

On Sun, Mar 2, 2008 at 7:12 PM, Ilan Berci <coder68@yahoo.com> wrote:

Aaron Turner wrote:
> On Thu, Feb 28, 2008 at 8:48 PM, Arlen Cuss <celtic@sairyx.org> wrote:
>> >> puts "looping"

>> => #<DRb::lots of rubbish here>>
>>

>> Arlen
>>
>
> Hmm... no, it's not output buffering. What OS/ruby ver are you on?
> I'm on Linux/1.8.6.

Before you check the OS, take a look at the code, your version is
calling:
self.clean_workers while Arlens is printing to the screen...

The first place I would look is clean_workers() and ask yourself if it's
logging, throwing, stuck, interrupted, etc..

rdebug would then be your second place to visit

--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing & replay tools for Unix
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety. -- Benjamin Franklin