title: How to pass an object to a process created using Multiprocess.Process
body: <p>I have a image-processing service containing two methods, which I want to execute in parallel using the multiprocessing library in Python.</p>
  <p>The first-method does an api call in order to fetch image metadata from an external service.</p>
  <p>The second method uses an object of a class which performs certain complex operations such as reading an image using the opencv library and also performing an image classification activity using a sklearn model</p>
  <p>The first function looks like this (as shown below) --&gt;</p>
  <pre><code>def function_1():
    ##perform long running api call
  </code></pre>
  <p>and this is my second function --&gt;</p>
  <pre><code>def function_2(image_proc_obj):
    predictions = image_proc_obj.predict()
  
  </code></pre>
  <p>On calling these two methods using <strong>multiprocessing.Process</strong> as shown below</p>
  <pre><code>image_proc_obj = ImageProcessingClass()
  p1 = multiprocessing.Process(target=function_1)
  p2 = multiprocessing.Process(target=function_2, args=(image_proc_obj,))
  
  </code></pre>
  <p>I am getting a <em><strong>ValueError: ctypes objects containing pointers cannot be pickled</strong></em></p>
  <p>I am passing the <strong>image_proc_obj</strong> in the second function because the constructor call of this class loads the model file which I don't want to happen on every function call.</p>
  <p>I also tried creating a class in this manner by subclassing multiprocess.Process</p>
  <pre><code>class ImageClassifier(multiprocess.Process):
     def __init__(self, process_obj):
        super(ImageClassifier,self).__init__()
         self.proc_obj = process_obj
  
  
     def run(self, image):
        predictions = self.proc_obj.predict(image)
  
  </code></pre>
  <p>But on running the commands as shown below:</p>
  <pre><code>image_proc_obj = ImageProcessingClass()
  classifier = ImageClassifier(name=&quot;classifier process&quot;, process_obj=image_proc_obj)
  classifier.start()
  classifier.join()
  </code></pre>
  <p>I get the same error --&gt; <em><strong>ValueError: ctypes objects containing pointers cannot be pickled</strong></em></p>
  <p>Looking forward to some help with this</p>