views:

739

answers:

3

Is there a module for Ruby that makes it easy to share objects between multiple processes? I'm looking for something similar to Python's multiprocessing, which supports process-safe queues and pipes that can be shared between processes.

+1  A: 

Combining DRb, which provides simple inter-process communication, with Queue or SizedQueue, which are both threadsafe queues, should give you what you need.

You may also want to check out beanstalkd which is also hosted on github

John Douthat
+1  A: 

I think you can do a lot of what you want using the facilities of Ruby IO; you're sharing between processes, not threads, correct?

If that's the case, IO.pipe will do what you need. Ruby doesn't have any built-in way of handling cross-process queues (to my knowledge), but you can also use FIFOs (if you're on Unix).

If you want something more fine-grained, and with good threading support, I'm fairly certain that you can piggyback on java.util.concurrent if you use JRuby. MRI has pretty lousy threading/concurrency support, so if that's what your aiming for, JRuby is probably a better place to go.

Don Werve
+1  A: 

I've run into this library but I haven't tried it yet.

Parallel::ForkManager — A simple parallel processing fork manager.

http://parallelforkmgr.rubyforge.org/

ShiningRay