从分叉的流程返回数据 [英] Returning data from forked processes
本文介绍了从分叉的流程返回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我这样做
Process.fork do
x
end
我怎么知道x返回了什么(例如true/fase/string)?
how can I know what x returned (e.g. true/fase/string) ?
(不能选择写入文件/数据库...)
(Writing to a file/database is not an option...)
推荐答案
我将在此过程中发现的所有解决方案(一些其他问题,例如用户退出+管道缓冲)包装到
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
或
results = Parallel.map([1,2,3],:in_threads=>4) do |i|
execute_something(i)
end
这篇关于从分叉的流程返回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文