grosser grosser - 6 months ago 10
Ruby Question

Returning data from forked processes

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 option...)

Answer

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