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")
$ 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
···
On 23 Jul 2005, at 01:10, john casu wrote:
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.
--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04