Class: Zold::Farmers::Fork
- Inherits:
-
Object
- Object
- Zold::Farmers::Fork
- Defined in:
- lib/zold/node/farmers.rb
Overview
In a child process using fork
Instance Method Summary collapse
-
#initialize(log: Log::NULL) ⇒ Fork
constructor
A new instance of Fork.
- #up(score) ⇒ Object
Constructor Details
Instance Method Details
#up(score) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/zold/node/farmers.rb', line 62 def up(score) start = Time.now stdout, stdin = IO.pipe pid = Process.fork do stdin.puts(score.next) end at_exit { Farmers.kill(@log, pid, start) } Process.wait stdin.close text = stdout.read.strip stdout.close raise "No score was calculated in the process ##{pid} in #{Age.new(start)}" if text.empty? after = Score.parse(text) @log.debug("Next score #{after.value}/#{after.strength} found in proc ##{pid} \ for #{after.host}:#{after.port} in #{Age.new(start)}: #{after.suffixes}") after end |