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

Already on GitHub? Sign in to your account

File handler leak with Tiff CCITT Group4 format #526

Closed
vieillecarne opened this Issue Feb 18, 2014 · 5 comments

Comments

Projects
None yet
3 participants

The handler to a Tiff CCITT Group4 file is not released properly. The code below gives an example. At the end the program holds waiting for the user to press "enter". At that moment, I use "Process Explorer" to check the file handles. The first is not released while the second is. Bug ?

Python : 2.7
Pillow : 2.3.0
OS : Windows XP/7 (32 bits)

# -*- coding: Utf-8 -*-
import sys
from PIL import Image

with open("mypath\\0000700.tif", "rb") as f:
    imagef = Image.open(f)
    print imagef.size

with open("mypath\\0000700.jpg", "rb") as g:
    imageg = Image.open(g)
    print imageg.size

sys.stdin.readline()

Thanks
Laurent

Owner

wiredfool commented Feb 18, 2014

Pillow doesn't currently support with. It handles the lazy reading and closing of the files as necessary.

How do you explain that the handle is released at the end for the jpg file and not for the tiff one ?

Owner

aclark4life commented Mar 17, 2014

@wiredfool Can you explain why Pillow doesn't support the use of the with statement? I'm curious

@aclark4life aclark4life added the bug label Mar 17, 2014

@aclark4life aclark4life added this to the Future milestone Mar 17, 2014

Owner

wiredfool commented Mar 17, 2014

Well, there are many reasons:

  1. there's no enter or exit.
  2. there's no close either, since it's managed in each backend.

I have a branch where I implemented with to prevent the warning on unclosed files, but I'm being kind of aggressive about closing and disposing of the image data. It's an approach, I'm not sure if it's the right one.

Owner

aclark4life commented Mar 17, 2014

IC, thanks

@wiredfool wiredfool modified the milestone: 2.4.0, Future Mar 20, 2014

@wiredfool wiredfool self-assigned this Mar 20, 2014

@wiredfool wiredfool added a commit to wiredfool/Pillow that referenced this issue Mar 28, 2014

@wiredfool wiredfool Tests for #526 b73b4a7

@wiredfool wiredfool added a commit to wiredfool/Pillow that referenced this issue Mar 28, 2014

@wiredfool wiredfool close the fd, if possible. Fixes #526 9552d9b

@aclark4life aclark4life closed this in #580 Mar 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment