Sleeping threads don't wake up?

A

Aaron Turner

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
 
A

Arlen Cuss

[Note: parts of this message were removed to make it a legal post.]

Hi,
?> loop do
?> sleep 10
?> server.start_reaper
looping
looping
looping
looping

It may be output buffering.

Arlen
 
A

Aaron Turner

Hi,

=> true

?> loop do
?> sleep 10


?> server.start_reaper

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.


--
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
 
I

Ilan Berci

Aaron said:
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
 
A

Arlen Cuss

[Note: parts of this message were removed to make it a legal post.]

Hi,

Hmm... no, it's not output buffering. What OS/ruby ver are you on?
I'm on Linux/1.8.6.
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
 
A

Aaron Turner

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... :)


--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top