title: OpenCV + Python + multiprocessing won't work
body: <p>I think I found a bug in Python bindings for OpenCV, but since there is always a chance problem exists between the chair and the keyboard and not in the code, I thought to confirm here instead of submitting a ticket right away.</p>
  
  <p>Here is a simple script for processing a bunch of images in parallel:</p>
  
  <pre><code>import cv2
  import multiprocessing
  import glob
  import numpy
  
  def job(path, output):
  
      image = cv2.imread(path)
      image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  
      output.put(path)
  
  if __name__ == "__main__":
  
      main_image = cv2.imread("./image.png")
      main_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  
      output = multiprocessing.Queue()
  
      processes = []
  
      for path in glob.glob("./data/*"):
  
          process = multiprocessing.Process(
              target=job,
              args=(path, output))
  
          process.start()
          processes.append(process)
  
      for process in processes:
          process.join()
  
      # Collect all results
      results = [output.get() for process in processes]
  
      print 'Finished'
  </code></pre>
  
  <p>In this code <code>results = [output.get() for process in processes]</code> never finishes.
  Now the really weird part is that if I comment out the <code>main_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)</code> line, which should have no influence on parallel computations whatsoever, script does finish.</p>
  
  <p>Both <code>./image.png</code> and paths at <code>./data/</code> lead to ordinary images, about ~20 of them in total.
  I tried creating images in memory (<code>numpy.ones([100, 100, 3]).astype(numpy.float32)</code>) and that didn't produce the bug.</p>
  
  <p>I have similar code written in C++ and it runs just fine.
  My environment: OS X 10.10, OpenCV 3.0.0, Python 2.7</p>
  
  <p>So, am I doing something silly, or does this indeed appear to be a bug in OpenCV that manifests in parallel computations?</p>
  
  <hr>
  
  <p>Edit:
  I also tried an implementation using multiprocessing.Pool.map() and the result is the same. Here's the code</p>
  
  <pre><code>import cv2
  import multiprocessing
  import glob
  import numpy
  
  def job(path):
  
      image = cv2.imread(path)
      image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  
      return path
  
  if __name__ == "__main__":
  
      image = cv2.imread("./image.png")
      image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  
      paths = glob.glob("./data/*")
      pool = multiprocessing.Pool()
      result = pool.map(job, paths)
  
      print 'Finished'
  
      for value in result:
          print value
  </code></pre>
  
  <p>I was able to get correct results for such design with non-opencv tasks, so I strongly believe the problem is on opencv side. But please feel free to prove me wrong - I would love that since it would mean I don't have to resort to C++.</p>