Python-Wand Sequence Not Clearing From Memory

后端 未结 1 2059
日久生厌
日久生厌 2021-01-05 06:25

If I do the following

for root, dirs, files in os.walk(myDir):
  for myFile in files:
    with Image(filename=myFile         


        
相关标签:
1条回答
  • 2021-01-05 07:30

    First things first - file a bug with wand. The wand.image.Image.destroy is not cleaning up wand.image.Sequence in the event an image sequence was allocated. Good find!

    You are absolutely correct with main.sequence[0].destroy(); however, your only freeing the first allocated SingleImage in the sequence. So img.sequence[1:] is still setting in memory. A not-so-elegant solution would be to iterate & destroy all SingleImage's.

    for root, dirs, files in os.walk(myDir):
      for myFile in files:
        with Image(filename=myFile) as img:
          with Image(image=img) as main:
            first = True
            for frame in main.sequence:
               if first:
                 print frame.width
                 first = False
               frame.destroy()
    

    comment: Reading an image from file to img, copying the data to main, and creating sub-images in a sequence seems very memory intensive. I'm sure your doing a lot more than identifying the image width, but can that be rewritten? Imagemagick does have a ping method ( not yet implemented in wand ) which doesn't read image data into memory.

    0 讨论(0)
提交回复
热议问题