title: How can I restrict the scope of a multiprocessing process?
body: <p>Using python's <a href="https://docs.python.org/2/library/multiprocessing.html" rel="noreferrer"><code>multiprocessing</code></a> module, the following contrived example runs with minimal memory requirements:</p>
  
  <pre><code>import multiprocessing 
  # completely_unrelated_array = range(2**25)
  
  def foo(x):
      for x in xrange(2**28):pass
      print x**2
  
  P = multiprocessing.Pool()
  
  for x in range(8):
      multiprocessing.Process(target=foo, args=(x,)).start()
  </code></pre>
  
  <p>Uncomment the creation of the <code>completely_unrelated_array</code> and you'll find that each spawned process allocates the memory for a copy of the <code>completely_unrelated_array</code>! This is a minimal example of a much larger project that I can't figure out how to workaround; multiprocessing seems to make a copy of everything that is global. I <strong>don't</strong> need a shared memory object, I simply need to pass in <code>x</code>, and process it <em>without</em> the memory overhead of the entire program.</p>
  
  <p><em>Side observation</em>: What's interesting is that <code>print id(completely_unrelated_array)</code> inside <code>foo</code> gives the same value, suggesting that somehow that might not be copies...</p>