remoteD is an easy to use interface for forked multi-process programming. It provides a simple dictionary interface for accessing data shared between processes and is capable of auto starting a server process when needed. Any python object that can be pickled can be stored in a remoteD 'share'. The name comes from the idea of a remote Dictionary object, which is the interface provided to your program. reads and writes are atomic, and explicit locking is available for situations that call for multi-command consistency.
remoteD is installed via the distutils package using the normal python setup.py mechanism. The full instructions for installing remoteD are:
remoteD is currently distributed under a (new) BSD style license. to view the full text of this license click here. Commercial support and customization of remoteD is available, please contact NeuroKode Labs, LLC for more information.
Constants:
UNIXSOCK - used to represent a UNIX socket type
IPSOCK - used to represent a IP socket type
DEFAULTSOCK - normally IPSOCK
# example #1
# hello world with remoteD
import remoteD, time
SharedD = remoteD.initShare()
def child_function(Shared, arg1, arg2):
Shared["myresult"] = "Hello World"
SharedD.newProc(child_function, [arg1, arg2])
while not SharedD.has_key("myresult"):
time.sleep(0.2)
print "The other process got '" + SharedD["myresult"] + "' as the answer"
Notes and considerations.
remoteD is fast - over 1.5k processes were created and connected to a single share-server on a 1GHz P3 machine using UNIXSOCK sockets, very little slowdown was observed. Slowdown occurs when physical memory is exhausted by the number of processes running.
SharedD['bar'] = 5
foo = SharedD['bar'] # foo now contains the value 5
foo += 2 # foo is now 7, SharedD['bar'] is still 5
Thus you must explicitly write changes back to the server when you are complete, in this case you'd just assign back to SharedD['bar'].
foo = SharedD['bar'] / SharedD['sue']
print str(SharedD['bar']) + " divided by " + str(SharedD['sue']) + " is " + foo
Each key is accessed twice on the server. Instead, you should do:
bar = SharedD['bar']
sue = SharedD['sue']
foo = bar / sue
print str(bar) + " divided by " + str(sue) + " is " + str(foo)
This is faster since local copies of the variables are used. Additionally, if another process were to change the value of 'sue' or 'bar' between the division and print line in the original example you could see an inconsistent answer printed, possibly "5 divided by 8 is 2"!
Shared['bar'] = Shared['bar'] + 1
Other processes could be futzing with bar between the read and the write to the share server.