什么是Ruby相当于Python的多处理模块? [英] What is Ruby's equivalent to Python's multiprocessing module?
问题描述
为了在Ruby或Python中获得真正的并发性,我需要创建新的进程。 Python使用 multiprocessing
模块非常简单,它抽象出所有的fork / wait goodness,让我专注于我的代码。 Ruby有类似的东西吗?现在我正在调用 Process.fork
和 Process.wait
来获得我的并发,我想要一个更清洁的解决方案。
To get real concurrency in Ruby or Python, I need to create new processes. Python makes this pretty straightforward using the multiprocessing
module, which abstracts away all the fork / wait goodness and lets me concentrate on my code. Does Ruby have something similar? Right now I am calling Process.fork
and Process.wait
to get my concurrency, and I want a cleaner solution.
推荐答案
我使用了 https://github.com/grosser/parallel ,喜欢它很多。默认情况下,它将#map或#each在系统中的所有核心。在引擎盖下,它是一个包装Process.fork,听起来像你要求的。
I have used https://github.com/grosser/parallel, and like it a lot. It will #map or #each across all the cores in your system by default. Under the hood it's a wrapper around Process.fork, which sounds like what you're asking for.
这篇关于什么是Ruby相当于Python的多处理模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!