I have some code that does (independent) operations on a bunch of Python Imaging Library (PIL) Image objects. I would like to try and speed this up using parallel processing, so I read up on the multiprocessing module below:
http://docs.python.org/library/multiprocessing.html
But it’s still not very clear to me how to use multiprocessing for this problem.
Conceptually, it looks like I could use a multiprocessing.Queue of Image objects and use a Pool of workers. But the Image objects seem ‘unpickelable’:
UnpickleableError: Cannot pickle <type 'ImagingCore'> objects
Is there a better way to process PIL images in parallel?
If you get the image objects from files, you can just send the filenames to the workers and let them open the images themselves.
Otherwise, you can send the image data (with
Image.getdata()), along with the size and pixel format, and have the workers reconstruct the image usingImage.new()andImage.putdata().