title: Get address of read-only mmap object
body: <p>I'm currently working on <a href="https://github.com/JaggedVerge/mmap_backed_array" rel="noreferrer">some code</a> that shares some state between processes using a <a href="https://docs.python.org/3/library/mmap.html" rel="noreferrer"><code>mmap</code></a> object. The use case is a bunch of processes that have access to some read-only data in a shared mmap backed array. Part of this involves doing some arithmetic on the underlying memory representation, I'm using ctypes much like in <a href="https://stackoverflow.com/questions/32364876/how-to-get-the-address-of-mmap-ed-memory-in-python">this question</a> to get a the underlying memory address.</p>
  
  <p>I have a situation where want to be able to open this mmap file as read only by the processes that only read data. However when I do that I'm not sure how to get the pointer address in that case. The following is as close to a minimal example of this problem as I can make:</p>
  
  <pre><code>import mmap
  import ctypes
  
  filename = "test"
  
  with open(filename, 'rb+') as fd:
      buf = mmap.mmap(fd.fileno(), 0)
      int_pointer = ctypes.c_int.from_buffer(buf)
  
  with open(filename, 'rb') as fd:
      test_mmap_ro = mmap.mmap(
          fd.fileno(), 0, access=mmap.ACCESS_READ,
          )
      int_pointer2 = ctypes.c_int.from_buffer(test_mmap_ro) #fails here
  </code></pre>
  
  <p>Running on Python3 this fails with this:</p>
  
  <pre><code>TypeError: must be read-write buffer, not mmap.mmap
  </code></pre>
  
  <p>While Python2 gives this:</p>
  
  <pre><code>TypeError: mmap can't modify a readonly memory map.
  </code></pre>
  
  <p>Given that I actually want to use a read only memory map how can I do this? I'll change to a writeable mmap if I have to, but I would rather not if there's another way to do this, so any suggestions or workarounds would be appreciated.</p>