A
Ara.T.Howard
any idea why this leaks memory?
require 'drb/drb'
require 'socket'
class JobRunner
include DRbUndumped
attr id
attr :command
def initialize command
@command = command
@pid = fork { exec @command }
end
end
class JobRunnerDaemon
def initialize
@runners = {}
end
def runner command
begin
r = JobRunner::new command
rescue Errno::ENOMEM
GC.start
r = JobRunner::new command
end
@runners[r.pid] = r
r
end
def wait r
pid, status = Process::waitpid2 r.pid, Process::WNOHANG|Process::WUNTRACED
@runners.delete pid
[pid, status]
end
end
$VERBOSE = nil
STDOUT.sync = true
port = Integer(ARGV.shift || (rand(8192 - 1025) + 1025))
uri = "druby://#{ Socket::gethostname }:#{ port }"
pid = fork
if pid
sleep 1
DRb.start_service nil, nil
jrd = DRbObject.new nil, uri
loop{ p(jrd.wait(jrd.runner('echo 42'))) }
else
DRb.start_service uri, JobRunnerDaemon::new
DRb.thread.join
end
when the child is waited on all resources should be freed and the hash entry
blown away - why the leak? what am i doing wrong here?
-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
===============================================================================
require 'drb/drb'
require 'socket'
class JobRunner
include DRbUndumped
attr id
attr :command
def initialize command
@command = command
@pid = fork { exec @command }
end
end
class JobRunnerDaemon
def initialize
@runners = {}
end
def runner command
begin
r = JobRunner::new command
rescue Errno::ENOMEM
GC.start
r = JobRunner::new command
end
@runners[r.pid] = r
r
end
def wait r
pid, status = Process::waitpid2 r.pid, Process::WNOHANG|Process::WUNTRACED
@runners.delete pid
[pid, status]
end
end
$VERBOSE = nil
STDOUT.sync = true
port = Integer(ARGV.shift || (rand(8192 - 1025) + 1025))
uri = "druby://#{ Socket::gethostname }:#{ port }"
pid = fork
if pid
sleep 1
DRb.start_service nil, nil
jrd = DRbObject.new nil, uri
loop{ p(jrd.wait(jrd.runner('echo 42'))) }
else
DRb.start_service uri, JobRunnerDaemon::new
DRb.thread.join
end
when the child is waited on all resources should be freed and the hash entry
blown away - why the leak? what am i doing wrong here?
-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
===============================================================================