I came up with an example of how Python's multiprocessing package -- standard in 2.6, and recently backported to 2.4 and 2.5 (on PyPI) -- could be used to set up a simple R-Tree index server:
from multiprocessing.managers import BaseManager class RtreeManager(BaseManager): pass RtreeManager.register('add') RtreeManager.register('intersection') if __name__ == '__main__': from rtree import Rtree class NoisyRtree(Rtree): def add(self, i, bbox): print "Adding: %s, %s" % (i, str(bbox)) Rtree.add(self, i, bbox) def intersection(self, bbox): print "Searching: %s" % str(bbox) return Rtree.intersection(self, bbox) index = NoisyRtree('processing') RtreeManager.register('add', index.add) RtreeManager.register('intersection', index.intersection) manager = RtreeManager(address=('', 50000), authkey='') server = manager.get_server() print "Server started" server.serve_forever()
Run that module (man.py) as a script to start the server, and access the index from Python in a new process like this:
Three items were already in my index, persisted on disk. One more can be added like this:
The manager synchronizes access so additions and queries from different processes don't clobber each other.