From: Ara.T.Howard@... Date: 2004-09-23T11:04:35+09:00 Subject: Re: DrbUndumped and GC On Thu, 23 Sep 2004, Masatoshi SEKI wrote: > How about TimerIdConv? > > require 'drb/timeridconv' > > .... > > DRb.install_id_conv(DRb::TimerIdConv.new) > DRb.start_service(....) > > > I like the following simple approach. > > class Server > def initialize > @proxy = Proxy.new > end > def method > @proxy > end > end in my case the code is require 'drb' require 'detach' class JobRunner #{{{ include DRbUndumped attr :job attr :jid attr :cid alias pid cid attr :shell attr :command attr :status def initialize job #{{{ @status = nil @job = job @jid = job['jid'] @command = job['command'] @shell = job['shell'] || 'bash' @r,@w = IO.pipe @cid = #Util::fork do fork do @w.close STDIN.reopen @r if File::basename(@shell) == 'bash' || File::basename(@shell) == 'sh' exec [@shell, "__rq_job__#{ @jid }__#{ File.basename(@shell) }__"], '--login' else exec [@shell, "__rq_job__#{ @jid }__#{ File.basename(@shell) }__"], '-l' end end @r.close #}}} end def run #{{{ @w.puts @command @w.close #}}} end def wait2 flags = 0 #{{{ pid, status = Process::waitpid2 @cid, flags @status = status [pid, status] #}}} end def wait flags = 0 #{{{ wait2(flags).last #}}} end #}}} end class JobRunnerDaemon #{{{ class << self #{{{ def new(*a,&b) #{{{ super(*a,&b).detach(:background=>false) #}}} end #}}} end def runner(*a,&b) #{{{ JobRunner::new(*a,&b) #}}} end alias new_runner runner alias runner_new runner %w( wait wait2 waitpid waitpid2 ).each do |m| eval "def #{ m }(*a,&b);Process::#{ m }(*a,&b);end" end #}}} end JobRunD = JobRunnerDaemon i need an object that can fork for me in another process. i can't fork in the current process due to some compilcations with sqlite and open files carried across forks. so i'm creating potentially dozens of these JobRunner objects and using jrd.wait to do a blocking wait on their completion (also some non-blocking waits but that's an impl detail). it works great now, i was just worrying about the GC - now i know i should be. because i should always do some sort of wait on the JobRunner's i can probably hook something into the 'def runner' method that registers the objects in a class datastructure (preventing gc) and hook something into the wait* methods that does the wait and removes them from this structure. i'll check out DRb::TimerIdConv tomorrow and get back to you. btw. thanks VERY much for the speedy reply! this mailing list is amazing! cheers. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================