[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Sleeping threads don't wake up?

Aaron Turner

2/29/2008 4:40:00 AM

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://s...
http://tcpreplay.s... - 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

5 Answers

Arlen Cuss

2/29/2008 4:48:00 AM

0

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

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

3/2/2008 6:00:00 PM

0

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
>

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


--
Aaron Turner
http://s...
http://tcpreplay.s... - 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

Ilan Berci

3/3/2008 3:12:00 AM

0

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

hth

ilan
--
Posted via http://www.ruby-....

Arlen Cuss

3/3/2008 12:15:00 PM

0

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


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

3/3/2008 5:05:00 PM

0

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

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


--
Aaron Turner
http://s...
http://tcpreplay.s... - 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