Catching DRb exceptions ??

Discussion in 'Ruby' started by john casu, Jul 23, 2005.

  1. john casu

    john casu Guest

    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")
    john casu, Jul 23, 2005
    #1
    1. Advertising

  2. john casu

    Eric Hodel Guest

    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.


    $ 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

    --
    Eric Hodel - - http://segment7.net
    FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
    Eric Hodel, Jul 24, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miles Keaton
    Replies:
    3
    Views:
    170
    Miles Keaton
    Mar 30, 2005
  2. Kirk Haines

    More DRb; SSL & DRB & errors

    Kirk Haines, Jul 1, 2005, in forum: Ruby
    Replies:
    0
    Views:
    115
    Kirk Haines
    Jul 1, 2005
  3. Guillaume Kwi

    DRb and catching connection close

    Guillaume Kwi, Jan 19, 2007, in forum: Ruby
    Replies:
    0
    Views:
    94
    Guillaume Kwi
    Jan 19, 2007
  4. J. Wook
    Replies:
    16
    Views:
    270
    Robert Klemme
    May 16, 2007
  5. Ittay Dror
    Replies:
    1
    Views:
    121
    Ittay Dror
    Oct 21, 2008
Loading...

Share This Page