Catching DRb exceptions ??

J

john casu

I have a simple problem.
I want to launch a DRb server from my program (in my case a parallel MPI program,
where the zero rank process is the actual DRb server), and then connect to it.

If I place a long enough sleep before invoking DRbObject.new, then everything
is groovy, and things proceed as intended. If I don't, then I get a DRbConnError
exception when DRB tries to connect to the server (which hasn't started up yet)

My problem is that I am unable to catch the exception that DRbObject.new raises
(i.e, I never see the "got exception" message in the attached code below), and
hence I am at the mercy of race conditions for this to work in a consistent way
without an excessively long sleep.

Can anyone please point out to me where I'm being a moron, and what I'm doing wrong ?
I'm running ruby-1.8.3 on Fedora Core 4 Linux.

Thanks,

john c.

-------------------------------------------------------------------

require 'drb'
require 'thread'

foo_serve = Thread.new do
system("/bin/bash -c \"foo_server\"")
end


# sleep 5.0

DRb.start_service
foo = nil

until (foo)
begin
foo = DRbObject.new(nil, 'druby://hobbes:7777')
rescue StandardError, DRbConnError
p "got exception"
ensure
sleep 0.05
end
end

puts foo.call_remote_foo(0, "run")
puts foo.call_remote_foo(0, "exit")
 
E

Eric Hodel

I have a simple problem.
I want to launch a DRb server from my program (in my case a
parallel MPI program,
where the zero rank process is the actual DRb server), and then
connect to it.

If I place a long enough sleep before invoking DRbObject.new, then
everything
is groovy, and things proceed as intended. If I don't, then I get
a DRbConnError
exception when DRB tries to connect to the server (which hasn't
started up yet)

My problem is that I am unable to catch the exception that
DRbObject.new raises
(i.e, I never see the "got exception" message in the attached code
below), and
hence I am at the mercy of race conditions for this to work in a
consistent way
without an excessively long sleep.

Can anyone please point out to me where I'm being a moron, and what
I'm doing wrong ?
I'm running ruby-1.8.3 on Fedora Core 4 Linux.

$ ruby drb.rb
/usr/local/lib/ruby/1.8/drb/drb.rb:733:in `open': druby://hobbes:7777
- #<SocketError: getaddrinfo: No address associated with nodename>
(DRb::DRbConnError)
from /usr/local/lib/ruby/1.8/drb/drb.rb:726:in `each'
from /usr/local/lib/ruby/1.8/drb/drb.rb:726:in `open'
from /usr/local/lib/ruby/1.8/drb/drb.rb:1186:in `initialize'
from /usr/local/lib/ruby/1.8/drb/drb.rb:1166:in `open'
from /usr/local/lib/ruby/1.8/drb/drb.rb:1082:in
`method_missing'
from /usr/local/lib/ruby/1.8/drb/drb.rb:1081:in `with_friend'
from /usr/local/lib/ruby/1.8/drb/drb.rb:1081:in
`method_missing'
from drb.rb:5
^^^^^^^^
[ ~ ]
[16:14] drbrain@kaa$ cat -n drb.rb
1 require 'drb'
2
3 DRb.start_service
4 foo = DRbObject.new(nil, 'druby://hobbes:7777')
5 puts foo.call_remote_foo(0, "run")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6

DRb doesn't attempt to connect until you try to use the remote object.

You may want to look into Rinda to automatically find live DRb services:

http://segment7.net/projects/ruby/drb/rinda/ringserver.html
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top