title: Giving access to shared memory after child processes have already started
body: <p>How do I give child processes access to data in shared memory if the data is only available after the child processes have been spawned (using <a href="http://docs.python.org/library/multiprocessing.html#the-process-class" rel="nofollow noreferrer">multiprocessing.Process</a>)?</p>
  
  <p>I am aware of <a href="http://docs.python.org/library/multiprocessing.html#multiprocessing.sharedctypes.RawArray" rel="nofollow noreferrer">multiprocessing.sharedctypes.RawArray</a>, but I can't figure out how to give my child processes access to a <code>RawArray</code> that is created after the processes have already started. </p>
  
  <p>The data is generated by the parent process, and the amount of data is not known in advance.</p>
  
  <p>If not for the <a href="http://wiki.python.org/moin/GlobalInterpreterLock" rel="nofollow noreferrer">GIL</a> I'd be using threading instead which will make this task a little simpler. Using a non-CPython implementation is not an option.</p>
  
  <hr>
  
  <p>Looking under the hood of <a href="http://svn.python.org/view/python/tags/r27rc2/Lib/multiprocessing/sharedctypes.py?revision=82139&amp;view=markup" rel="nofollow noreferrer">muliprocessing.sharedctypes</a>, it looks like shared ctype objects are allocated <a href="http://svn.python.org/view/python/tags/r27rc2/Lib/multiprocessing/heap.py?view=markup" rel="nofollow noreferrer">using <code>mmap</code>ed memory</a>. </p>
  
  <p>So this question really boils down to: <strong>Can a child process access an anonymously mapped memory if <code>mmap()</code> was called by the parent after the child process was spawned?</strong></p>
  
  <p>That's somewhat in the vein of what's being asked in <a href="https://stackoverflow.com/questions/4991533/sharing-memory-between-processes-through-the-use-of-mmap">this question</a>, except that in my case the caller of <code>mmap()</code> is the parent process and not the child process.</p>
  
  <hr>
  
  <h3>(Solved)</h3>
  
  <p>I created my own version of <code>RawArray</code> that uses <code>shm_open()</code> under the hood. The resulting shared ctypes array can be shared with any process as long as the identifier (<code>tag</code>) matches. </p>
  
  <p>See <a href="https://stackoverflow.com/questions/7419159/giving-access-to-shared-memory-after-child-processes-have-already-started/7447103#7447103">this answer</a> for details and an example.</p>