Returning data from forked processes

后端 未结 7 880
别那么骄傲
别那么骄傲 2020-12-08 14:37

If I do

Process.fork do 
  x 
end 

how can I know what x returned (e.g. true/fase/string) ?

(Writing to a file/database is not an

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 15:20

    Thanks for all the answers, I got my solution up and running, still need to see how to handle non-forking environments, but for now it works :)

    read, write = IO.pipe
    Process.fork do
      write.puts "test"
    end
    Process.fork do
      write.puts 'test 2'
    end
    
    Process.wait
    Process.wait
    
    write.close
    puts read.read
    read.close
    

    you can see it in action @ parallel_specs Rails plugin

提交回复
热议问题