MultiProcessing with self.methods
<p>Using <code>multiprocessing</code> on methods we get error stating <code>self.methods cannot be pickled</code>.</p>
<p>To overcome this I used:</p>
<pre><code>def _pickle_method(m):
    if m.im_self is None:
        return getattr, (m.im_class, m.im_func.func_name)
    else:
        return getattr, (m.im_self, m.im_func.func_name)


copy_reg.pickle(types.MethodType, _pickle_method)
</code></pre>
<p>Now I searched about this, but few questions are still unclear:</p>
<ol>
<li>Why can't <code>self.methods</code> be pickled?</li>
<li>How does <code>copy_reg.pickle()</code> work? How does it enable pickling of <code>self.methods</code>?</li>
<li>Are there any negatives of using this approach or are there any other, better, methods?</li>
</ol>
<p>More Info:</p>
<p>I had a function in a class which used to do a <code>request.get</code> and <code>request.post</code>. To improve times , I used <code>multiprocessing</code> over it.
This is the exact problem I faced.</p>
<p><a href="https://stackoverflow.com/q/1816958/3679490">Can't pickle &lt;type 'instancemethod'&gt; when using multiprocessing Pool.map()</a></p>