Python multiprocessing: cPickle.PicklingError: Can't pickle <type 'instancemethod'>
<p>I am trying to use python <code>multiprocessing</code> module to process a large set of urls for which I am creating worker processes using a <code>multiprocessing.Pool</code> object as shown below.</p>

<pre><code>from multiprocessing import Pool, TimeoutError, cpu_count

class MyClass:
    def square(self, x):
        return x*x

    @staticmethod
    def getNumbers():
        return range(10)

    def calculate(self):
        pool = Pool(processes=min(cpu_count(),8))
        results = [pool.apply(self.square,(i,)) for i in self.getNumbers()]
        pool.close()
        pool.join()
        for result in results:
            print result


if __name__ == '__main__':
    instance = MyClass()
    instance.calculate()
</code></pre>

<p>However the above piece of code results in a pickling error as follows:</p>

<pre><code>Traceback (most recent call last):
  File "multi.py", line 24, in &lt;module&gt;
    instance.calculate()
  File "multi.py", line 15, in calculate
    results = [pool.apply(self.square,(i,)) for i in self.getNumbers()]
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 244, in apply
    return self.apply_async(func, args, kwds).get()
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 558, in get
    raise self._value
cPickle.PicklingError: Can't pickle &lt;type 'instancemethod'&gt;: attribute lookup __builtin__.instancemethod failed
</code></pre>

<p><strong>NOTE</strong>
A similar question has been asked previously on SO by someone else but remains unanswered: <a href="https://stackoverflow.com/questions/33107756/cpickle-picklingerror-cant-pickle-type-instancemethod-attribute-lookup">cPickle.PicklingError: Can&#39;t pickle &lt;type &#39;instancemethod&#39;&gt;: attribute lookup __builtin__.instancemethod failed</a></p>

<p><strong>EDIT</strong> Gave a better sample code example</p>