readonly
readonly

Reputation: 355984

Working with multiple processes in Ruby

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.

Upvotes: 4

Views: 4505

Answers (3)

John Douthat
John Douthat

Reputation: 41209

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

Upvotes: 1

ShiningRay
ShiningRay

Reputation: 1008

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/

Upvotes: 2

Don Werve
Don Werve

Reputation: 5120

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.

Upvotes: 3

Related Questions