在Python中,给定一个全尺寸图像目录,如何使用多个CPU内核生成缩略图?

ens*_*are 2 python multithreading python-multithreading

我有一个16核的机器,但我目前的调整大小功能只使用一个核心,这对于大型图像目录来说效率非常低.

def generateThumbnail(self, width, height):
     """
     Generates thumbnails for an image
     """
     im = Image.open(self._file)
     (detected_width,detected_height) = im.size

     #Get cropped box area
     bbox = self.getCropArea(detected_width, detected_height, width, height)

     #Crop to box area
     cropped_image = im.crop(bbox)

     #Resize to thumbnail
     cropped_image.thumbnail((width, height), Image.ANTIALIAS)

     #Save image
     cropped_image.save(self._path + str(width) + 'x' +
             str(height) + '-' + self._filename, "JPEG")
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.谢谢.

Rya*_*rom 5

对于使用线程接口的多处理模块来说,这听起来是一个很好的解决方案,但是创建了单独的进程而不是线程.