title: How can I mmap HDF5 data into multiple Python processes?
body: <p>I am trying to load HDF5 data from a memory cache (memcached) or the network, and then query it (read only) from multiple Python processes, <em>without</em> making a separate copy of the whole data set. Intuitively I would like to mmap the image (as it would appear on disk) into the multiple processes, and then query it from Python.</p>
  
  <p>I am finding this difficult to achieve, hence the question. Pointers/corrections appreciated.</p>
  
  <h2>Ideas I have explored so far</h2>
  
  <ul>
  <li><strong>pytables</strong> - This looks the most promising, it supports rich interface for querying HDF5 data and it (unlike numpy) seems to work with the data without making a (process local) copy of the data. It even supports a method <code>File.get_file_image()</code> which would seem to get the file image. What I don't see how to construct a new File / FileNode from a memory image rather than a disk file.</li>
  <li><strong>h5py</strong> - Another way to get at HDF5 data, as with pytables, it seems to require a disk file. The option driver='core' looks promising, but I can't see how to provide an existing mmap'd region into it, rather than have it allocate its own.</li>
  <li><strong>numpy</strong> - A lower level approach, if I share my raw data via mmap, then I might be able to construct a numpy ndarray which can access this data. But the relevant constructor <code>ndarray.__new__(buffer=...)</code> says it will copy the data, and numpy views can only seem to be constructed from existing ndarrays, not raw buffers.</li>
  <li><strong>ctypes</strong> - Very lowest level approach (could possibly use multiprocessing's <code>Value</code> wrapper to help a little). If I use ctypes directly I can read my mmap'd data without issue, but I would lose all the structural information and help from numpy/pandas/pytables to query it.</li>
  <li><strong>Allocate disk space</strong> - I could just allocate a file, write out all the data, and then share it via pytables in all my processes. My understanding is this would be memory efficient because pytables doesn't copy (until required) and obviously the processes would share the OS disk cache of the underlying file image. My objection is it is ugly and brings disk I/O into what I would like to be a pure memory system.</li>
  </ul>