title: Multiprocessing a loop of a function that writes to an array in python
body: <p>I'm trying to implement multiprocessing for this loop. It fails to modify the array or and does not seem to order the jobs correctly (returns array before last function done). </p>
  
  <pre><code>import multiprocessing
  import numpy
  
  
  def func(i, array):
      array[i] = i**2
      print(i**2)
  
  def main(n):
      array = numpy.zeros(n)
  
      if __name__ == '__main__':
          jobs = []
          for i in range(0, n):
              p = multiprocessing.Process(target=func, args=(i, array))
              jobs.append(p)
              p.start()
  
      return array
  
  print(main(10))
  </code></pre>