Answer the question
In order to leave comments, you need to log in
Ruby - what are the specifics of how threads work?
Hello! There is a certain process which should work constantly, but can hang. I want to write a Ruby script that will launch this process and check its work in a separate thread at a certain interval (in a special way)
class PingWatchdog
def initialize(server)
Thread.new {
while true do
unless LaLaLa.test?(IP, PORT, PING_TIMEOUT)
server.stop
end
sleep WATCHDOG_DELAY
end
}
end
end
class ServerProcess
def initialize(*opts)
@proc_pid = spawn(CMD)
@proc_thr = Process.detach(@proc_pid)
@watchdog = PingWatchdog.new self
end
def wait
@proc_thr.join
end
def command(data)
$stdout << "#{data}\n"
end
def kill
Process.kill('TERM', @proc_pid)
end
end
while true
server = ServerProcess.new
server.wait
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question