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?

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

On Thu, Feb 28, 2008 at 8:48 PM, Arlen C. [email protected] 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.

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

Aaron T. wrote:

On Thu, Feb 28, 2008 at 8:48 PM, Arlen C. [email protected] 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 Sun, Mar 2, 2008 at 7:12 PM, Ilan B. [email protected] wrote:

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

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