On 6/23/06, ara.t.howard / noaa.gov <ara.t.howard / noaa.gov> wrote:

[ cut]
>    #
>    # fork a few children - each one tears down and sets up client again
>    #
>      3.times do
>        cid = fork
>        unless cid
>          DRb.stop_service
>          DRb.start_service
>          dhash = DRbObject.new nil, uri
>          dhash['children'] << Process.pid
>          exit
>        else
>          Process.wait
[ cut]
Hi Ara,

The problem with this approach is that you have to know the uri of the
server at fork time, which can be a problem.
(And I didn't realize that you can destroy a DRbObject with
DRb.stop_service -- I associate that with the server side of things).

I've found a mote generic way of forking a process that is a DRb
client, but this has as drawback that it has an initimate knowlegde of
the way DRb is implemented.
module DRb
  class DRbConn
    def self.fork
      f = @mutex.synchronize do
        Process::fork
      end
      if f.nil?
        @pool = []
        if block_given?
          yield
          exit 0
        end
      end
      f
    end
  end
end

This just deletes the commection pool in the child.
Forking within the mutex is because it's possible to fork with some
other thread having the mutex locked, which causes problems for the
one-thread child.

But it's a bit of a kludge and I would prefer it if DRbObject had a
method to deal with it.

Thanks,

Han Holl