title: python multiprocessing : AttributeError: Can't pickle local object
body: <p>I have a method inside a class to return a func which parameters may change.</p>
  
  <p>The Interface function accept two parameters, f and its args.I want to use mp.pool to accelerate it.However, it returns an error.</p>
  
  <pre><code>from multiprocessing import Pool
  # from multiprocess import Pool
  # from pathos.multiprocessing import ProcessingPool as Pool
  import pickle
  import dill
  
  
  class Temp:
      def __init__(self, a):
          self.a = a
  
      def test(self):
          def test1(x):
              return self.a + x
  
          return test1
  
  
  def InterfaceFunc(f, x):
      mypool = Pool(4)
      return list(mypool.map(f, x))
  
  
  if __name__ == "__main__":
      t1 = Temp(1).test()
      x = [1, 2, 3, 1, 2]
  
      res1 = list(map(t1, x))
      print(res1)
  
      res2 = InterfaceFunc(t1, x)
  </code></pre>
  
  <p>it raise the same error:</p>
  
  <pre><code>AttributeError: Can't pickle local object 'Temp.test.&lt;locals&gt;.test1'
  </code></pre>
  
  <p>I have tried 3 method:</p>
  
  <p><a href="https://stackoverflow.com/questions/19984152/what-can-multiprocessing-and-dill-do-together">What can multiprocessing and dill do together?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/40234771/replace-pickle-in-python-multiprocessing-lib">Replace pickle in Python multiprocessing lib</a></p>
  
  <p><a href="https://stackoverflow.com/questions/52265120/python-multiprocessing-pool-map-attributeerror-cant-pickle-local-object">Python Multiprocessing Pool Map: AttributeError: Can&#39;t pickle local object</a></p>
  
  <p>Method 1, 2 :</p>
  
  <pre><code> from multiprocess import Pool
   from pathos.multiprocessing import ProcessingPool as Pool
  </code></pre>
  
  <p>It raise error:</p>
  
  <pre><code> File "E:\Users\ll\Anaconda3\lib\site-packages\dill\_dill.py", line 577, in _load_type
      return _reverse_typemap[name]
  KeyError: 'ClassType'
  </code></pre>
  
  <p>Method3 needs to change the code , however I cant simply move the func out of the class because I need f to be a parameter for the Interface.</p>
  
  <p>Do you have any suggestions? I'm an inexperienced newcomer. </p>