title: Python multiprocessing: shared memory and pickle issue
body: <p>I have already done some multiprocessing in the past, but this time, I can't figure out a workaround.</p>
  
  <p>I know that I can only pickle functions if they are at the top level of a module. This has always worked well so far, but now I have to work with shared memory in an instance and I don't see a way to move the function to the top level.</p>
  
  <p>Consider this</p>
  
  <pre><code>import numpy as np
  import multiprocessing
  from itertools import repeat
  
  class Test:
  
      def __init__(self, x, y):
          self.x = x
          self.y = y
  
      def my_task(self):
  
          # Create process pool
          p = multiprocessing.Pool(4)
  
          # Create shared memory arrays
          share1 = multiprocessing.Array("d", self.x, lock=False)
          share2 = multiprocessing.Array("d", self.y, lock=False)
  
          def mp(xc, yc, c):
  
              # This is just some random weird statement
              foo = np.sum(share1) + np.sum(share2) +xc + yc + c
              return foo
  
  
          def mp_star(args):
              return mp(*args)
  
          # Define some input for multiprocessing
          xs = [1,2,3,4,5]
          ys = [5,6,7,8,9]
          c = 10
  
          # Submit tasks
          result = p.map(mp_star, zip(xs, ys, repeat(c)))
  
          # Close pool
          p.close()
  
          return result
  
  
  
  # Get some input data
  x = np.arange(10)
  y = x**2
  
  # Run the thing
  cl = Test(x=x, y=y)
  cl.my_task()
  </code></pre>
  
  <p>You can see that I need to access shared data from the instance itself. For this reason I put the multiprocessing parts within the method 'my_task'. For this reason I get the typical pickle error </p>
  
  <pre><code>_pickle.PicklingError: Can't pickle &lt;function Test.my_task.&lt;locals&gt;.mp_star at 0x10224a400&gt;: attribute lookup mp_star on __main__ failed
  </code></pre>
  
  <p>which I already know about. I can't move the multiprocessing tasks to the top level though since I need to access the shared data. Also I want to keep the number of dependencies low so I need to work with the built-in multiprocessing libraries.</p>
  
  <p>I hope the code makes sense. So, how can I use the shared memory space from an instance in multiprocessing? Is there a way to move the functions to the top level?</p>