[ANN] process_shared -- Python's multiprocessing for Ruby

Hello all.

Patrick has been doing some excellent work on the “process_shared” gem,
which provides for cross process mutexes and shared memory, inspired by
Python’s multiprocessing library:

ex:

require ‘process_shared’
mutex = ProcessShared::Mutex.new
mem = ProcessShared::SharedMemory.new(:int)
mem.put_int(0, 0)

10.times {
fork do
puts “in process 1 (#{Process.pid})”
10.times do
sleep 0.01
mutex.synchronize do
value = mem.get_int(0)
sleep rand*0.1
puts “process 1 (#{Process.pid}) incrementing”
mem.put_int(0, value + 1)
end
end
end
}
Process.waitall
p mem.get_int(0) # always outputs 100

more advanced examples can be found in the specs:

It’s not quite “polished” but seems to work well for its use cases. It
has support for shared native primitives as well as “shared strings” to
use for marshalling more complex objects.

Thought I’d let people know of its existence. I’d also like to ask if
there are any other “features” that people would wish to see added to
the library (feel free to test it out, see how you like it). Anything
come to mind that would be useful?

Thanks!
-roger-

On Wed, Feb 1, 2012 at 11:49 AM, Roger P. [email protected]
wrote:

Hello all.

Patrick has been doing some excellent work on the “process_shared” gem,
which provides for cross process mutexes and shared memory, inspired by
Python’s multiprocessing library

Multiple processes, shared memory, and mutexes? Wow, it’s truly the
worst
of both worlds! :wink:

Patrick has been doing some excellent work on the “process_shared” gem,
which provides for cross process mutexes and shared memory, inspired by
Python’s multiprocessing library

Multiple processes, shared memory, and mutexes? Wow, it’s truly the
worst
of both worlds! :wink:

Well, actually it avoids sharing memory because of fork, thus avoiding
all of those odd race conditions. phew!
This just lets you farm out work more easily.

-roger-

Let me know if there’s any further interest in this project (shared
mutexes/queues/simpler parallel process mapping for MRI), and I’ll work
on it more.
In the meantime, go team ruby :stuck_out_tongue:
-roger-

Heh, I know. Don’t let me troll you too hard :wink:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs