title: Passing a list of class instances to multiprocessing.Pool and parallelize the running of method function of each class objects
body: <p>I have a list of class instances. Each of this class objects have a method function that I want to run and I want to parallelize across the class instances since there's a lot of them. For example, I have this class object:</p>
  
  <pre><code>class Person(object):
      def __init__(self, name):
          self.name = name
      def register(self):
          self.registered = True
  </code></pre>
  
  <p>Now I defined a list of class instances of <code>Person()</code></p>
  
  <pre><code>persons = [Person(i) for i in ["Bernard", "Enrik", "Joseph"]]
  </code></pre>
  
  <p>I want to parallelize the running of <code>Person.register()</code> method function across the values in persons. Using multiprocessing.Pool, here's what I did. Since you can't pickle method function, I wrap it in another function.</p>
  
  <pre><code>import multiprocessing as mp
  def reg(person):
      person.register()
  pool = mp.Pool(processes=mp.cpu_count()//2)
  res = list(pool.map(reg, persons))
  </code></pre>
  
  <p>The code runs without error by the way, so now I am expecting that every Person instance in the list will have an attribute <code>registered</code> set to <code>True</code> but when I check each class instance, it doesn't contain attribute <code>registered</code>. For example, checking if <code>registered</code> is an attribute of persons[0],</p>
  
  <pre><code>hasattr(persons[0], "registered")
  &gt;&gt;&gt; False
  </code></pre>
  
  <p>Why is this so? How can I solve this?</p>