Drb question

I am trying the distributed Ruby examples from PickAxe using
ruby 1.7.3 (2002-11-17) [i386-mswin32] and drb-2.0b1

The simple example works as expected.

But how do I stop the server gracefully?

Code as follows

Server Code: drb_srvr.rb

require ‘drb’

class TstSrvr
def time_now
"It is: " + Time.now().to_s
end

def bye(msg="")
    puts msg
    exit(1)
end

end

srvObj = TstSrvr.new
DRb.start_service(“druby://EMACHINE:5555”,srvObj)
DRb.thread.join

···

#--------------------------------------------
#Client Code: drb_client.rb
require 'drb’
STDOUT.sync = true

cliObj = DRbObject.new(nil,“druby://EMACHINE:5555”)

5.times { |i| puts cliObj.time_now; sleep(2); }

cliObj.bye

#-------------------------------------------
C:> ruby drb_srvr.rb

In a different command window:

C:> ruby drb_client.rb

It is: Mon Jan 13 21:35:33 Central Standard Time 2003
It is: Mon Jan 13 21:35:35 Central Standard Time 2003
It is: Mon Jan 13 21:35:37 Central Standard Time 2003
It is: Mon Jan 13 21:35:39 Central Standard Time 2003
It is: Mon Jan 13 21:35:41 Central Standard Time 2003
C:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:104:in load': connection closed (DRb::DRbConnError) from C:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:149:inrecv_reply’
from C:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:291:in recv_reply' from C:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:471:insend_message’
from C:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:405:in method_missing' from C:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:404:inopen’
from C:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:404:in `method_missing’
from C:/atest/drb_client.rb:8

Hi.

But how do I stop the server gracefully?

require ‘drb’

class TstSrvr
def time_now
"It is: " + Time.now().to_s
end

def bye(msg="")
    puts msg
    exit(1)
end

How about this?

def bye(msg=“”)
puts msg
Thread.new {
sleep(1)
exit(1)
}
end

After doing the changes you suggested, I still get:

C:\atest>ruby drb_client.rb
It is: Tue Jan 14 08:13:59 Central Standard Time 2003
It is: Tue Jan 14 08:14:01 Central Standard Time 2003
It is: Tue Jan 14 08:14:03 Central Standard Time 2003
It is: Tue Jan 14 08:14:05 Central Standard Time 2003
It is: Tue Jan 14 08:14:07 Central Standard Time 2003
c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:726:in current_server': DRb::DRbServerNotFound (DRb::DRbServerNotFound) from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:738:in uri’
from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:375:in initialize' from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:357:in new’
from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:357:in _load' from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:112:in load’
from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:112:in load' from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:150:in recv_reply’
from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:291:in recv_reply' from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:471:in send_message’
from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:405:in
method_missing' from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:404:in open’
from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:404:in
`method_missing’
from drb_client.rb:8

“Masatoshi SEKI” m_seki@mva.biglobe.ne.jp wrote in message
news:C2E68B6F-27B1-11D7-BC3C-000393814512@mva.biglobe.ne.jp…

···

Hi.

But how do I stop the server gracefully?

require ‘drb’

class TstSrvr
def time_now
"It is: " + Time.now().to_s
end

def bye(msg="")
    puts msg
    exit(1)
end

How about this?

def bye(msg=“”)
puts msg
Thread.new {
sleep(1)
exit(1)
}
end

it doesn’t work for me either - generates the same error as Shashank Date’s
try…
why? :))

i’m using ruby 1.6.8, drb 2.0b1, win32

pat

···

“Masatoshi SEKI” m_seki@mva.biglobe.ne.jp wrote

But how do I stop the server gracefully?
How about this?

def bye(msg=“”)
puts msg
Thread.new {
sleep(1)
exit(1)
}
end

After doing the changes you suggested, I still get:

C:\atest>ruby drb_client.rb
It is: Tue Jan 14 08:13:59 Central Standard Time 2003
It is: Tue Jan 14 08:14:01 Central Standard Time 2003
It is: Tue Jan 14 08:14:03 Central Standard Time 2003
It is: Tue Jan 14 08:14:05 Central Standard Time 2003
It is: Tue Jan 14 08:14:07 Central Standard Time 2003
c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:726:in current_server': DRb::DRbServerNotFound (DRb::DRbServerNotFound) from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:738:in uri’

hmm. drb_clent.rb does not initialize DRb.
but, I found minor bug in drb/drb.rb, without DRb.start_service.

Please try either of the followings.

(a) initialize DRb, in drb_client.rb. (recommend)

require ‘drb’
STDOUT.sync = true
DRb.start_service

cliObj = DRbObject.new(nil,“druby://localhost:5555”)

5.times { |i| puts cliObj.time_now; sleep(2); }

cliObj.bye

(b) patch drb/drb.rb.

— drb.rb 27 Dec 2002 23:28:25 -0000 1.92
+++ drb.rb 14 Jan 2003 21:24:03 -0000
@@ -372,7 +372,7 @@
@uri, option = DRbProtocol.uri_option(uri, DRb.config)
@ref = DRbURIOption.new(option) unless option.nil?
else

  •   @uri = uri ? uri : DRb.uri
    
  •   @uri = uri ? uri : (DRb.uri rescue nil)
      @ref = obj ? DRb.to_id(obj) : nil
     end
    
    end

(c) return nil (TstSrvr#bye)

···

def bye(msg=“”)
puts msg
Thread.new { sleep(1); exit(1) }
nil
end

After doing the changes you suggested, I still get:

C:\atest>ruby drb_client.rb
It is: Tue Jan 14 08:13:59 Central Standard Time 2003
It is: Tue Jan 14 08:14:01 Central Standard Time 2003
It is: Tue Jan 14 08:14:03 Central Standard Time 2003
It is: Tue Jan 14 08:14:05 Central Standard Time 2003
It is: Tue Jan 14 08:14:07 Central Standard Time 2003
c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:726:in current_server': DRb::DRbServerNotFound (DRb::DRbServerNotFound) from c:/ruby/lib/ruby/site_ruby/1.7/drb/drb.rb:738:in uri’

hmm. drb_clent.rb does not initialize DRb.
but, I found minor bug in drb/drb.rb, without DRb.start_service.

Please try either of the followings.

(a) initialize DRb, in drb_client.rb. (recommend)

require ‘drb’
STDOUT.sync = true
DRb.start_service

cliObj = DRbObject.new(nil,“druby://localhost:5555”)

5.times { |i| puts cliObj.time_now; sleep(2); }

cliObj.bye

(b) patch drb/drb.rb.

— drb.rb 27 Dec 2002 23:28:25 -0000 1.92
+++ drb.rb 14 Jan 2003 21:24:03 -0000
@@ -372,7 +372,7 @@
@uri, option = DRbProtocol.uri_option(uri, DRb.config)
@ref = DRbURIOption.new(option) unless option.nil?
else

  •   @uri = uri ? uri : DRb.uri
    
  •   @uri = uri ? uri : (DRb.uri rescue nil)
      @ref = obj ? DRb.to_id(obj) : nil
     end
    
    end

(c) return nil (TstSrvr#bye)

···

def bye(msg=“”)
puts msg
Thread.new { sleep(1); exit(1) }
nil
end

m_seki@mva.biglobe.ne.jp wrote in message

Please try either of the followings.

(a) initialize DRb, in drb_client.rb. (recommend)

require ‘drb’
STDOUT.sync = true
DRb.start_service

cliObj = DRbObject.new(nil,“druby://localhost:5555”)

5.times { |i| puts cliObj.time_now; sleep(2); }

cliObj.bye

Ok, did that !

(b) patch drb/drb.rb.

— drb.rb 27 Dec 2002 23:28:25 -0000 1.92
+++ drb.rb 14 Jan 2003 21:24:03 -0000
@@ -372,7 +372,7 @@
@uri, option = DRbProtocol.uri_option(uri, DRb.config)
@ref = DRbURIOption.new(option) unless option.nil?
else

  •   @uri = uri ? uri : DRb.uri
    
  •   @uri = uri ? uri : (DRb.uri rescue nil)
      @ref = obj ? DRb.to_id(obj) : nil
     end
    
    end

Skipped this patch initially … did not want to do it until necessary.

(c) return nil (TstSrvr#bye)

def bye(msg=“”)
puts msg
Thread.new { sleep(1); exit(1) }
nil
end

Did that, and yes now it is working like I wanted it to !

Thanks a lot.

I also tried the patch independently and of course, it worked too. But I
did not move it in our production environment.

I will let you decide if it needs to be refactored into your source.

Again thanks for the prompt help.

– shanko