Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker pillow memory leak #4364

Closed
l1351868270 opened this issue Jan 17, 2020 · 9 comments
Closed

docker pillow memory leak #4364

l1351868270 opened this issue Jan 17, 2020 · 9 comments
Labels

Comments

@l1351868270
Copy link

What did you do?

I run codes in docker and physical machine。

What did you expect to happen?

when i run codes in the docker, it is ok.

What actually happened?

In physical machine it is ok, but in the docker appears memory leak. When I debug, I find that the error is caused by the file WebPImagePlugin.py:60

self._decoder = _webp.WebPAnimDecoder(self.fp.read())

What are your OS, Python and Pillow versions?

  • OS: linux
  • Python: docker pull python:3.7.4
  • Pillow: 7.0.0 or 6.2.0
  • Image
    ChsEeV4fB3yALzXIAABC7Nmhuw8028
from PIL import Image
from PIL import ImageFile

img_file = r"./ChsEeV4fB3yALzXIAABC7Nmhuw8028.jpg"

ImageFile.LOAD_TRUNCATED_IMAGES = True
while True:
    try:
        im = Image.open(img_file)
    except Exception as e:
        # print("err={}".format(e))
        pass
@l1351868270 l1351868270 changed the title docker pillow memory docker pillow memory leak Jan 17, 2020
@radarhere
Copy link
Member

radarhere commented Jan 25, 2020

You're talking about a WebP image leak, and the file you have attached is WebP, but the sample code mentions a JPG?

It is also strange that your sample code uses an infinite loop. How many iterations does it take to show the leak?

Since you're suggesting something as subtle as a problem in one environment but not another, could you be more specific about the linux Docker image you used? Where did you get the image from? What flavour of Linux?

@homm
Copy link
Member

homm commented Jan 30, 2020

You shouldn't use Image.open(file_name), please use Image.open(file_object) instead or call im.close() manually. This is not a Pillow's leak, this is Python's leak. See #2019.

@homm
Copy link
Member

homm commented Jan 30, 2020

Sorry, this shouldn't be related since the filename isn't changing during the loop.

@homm
Copy link
Member

homm commented Jan 30, 2020

@radarhere this .jpg file is actually a webp image.

$ head ../imgs/72596141-57196f00-3946-11ea-8eb5-c0d2e261ce23.jpg -c 50
RIFFz?WEBPVP8 n?:?*h?>E?D??!???x8D????

@homm
Copy link
Member

homm commented Jan 30, 2020

Memory leaks with speed about 500 megabytes on 29000 iterations which is ≈17kb/it, the same as image file size.

@l1351868270
Copy link
Author

@homm I modify the WebPImagePlugin.py:43 like this "if _webp.HAVE_WEBPANIM:", thus delete the
"not". Now , it is ok!

@l1351868270
Copy link
Author

l1351868270 commented Feb 7, 2020

@homm When i modify the WebPImagePlugin.py:43, there is other question. Do you has a plan to solve the memory leak question.

@radarhere
Copy link
Member

While I don't encourage this as a solution, be aware that you can get that effect without modifying the Pillow source code.

from PIL import _webp, Image
_webp.HAVE_WEBPANIM = False
im = Image.open("Tests/images/hopper.webp")

@l1351868270
Copy link
Author

@homm thanks very much! Just take your suggestions, I modify my codes. Until now, it is ok!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants