Returning data from forked processes

后端 未结 7 867
别那么骄傲
别那么骄傲 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:25

    I wrapped all the solutions I found along the way (some other problems like user exiting + piping-buffers) into ruby parallel gem. Now it is as easy as:

    results = Parallel.map([1,2,3],:in_processes=>4) do |i|
      execute_something(i)
    end
    

    or

    results = Parallel.map([1,2,3],:in_threads=>4) do |i|
      execute_something(i)
    end
    

提交回复
热议问题