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

Image.load() does not close file pointer #1144

Closed
arve0 opened this issue Mar 21, 2015 · 7 comments
Closed

Image.load() does not close file pointer #1144

arve0 opened this issue Mar 21, 2015 · 7 comments
Labels
Anaconda Issues with Anaconda's Pillow Bug Any unexpected behavior, until confirmed feature. Enhancement File Closing

Comments

@arve0
Copy link

arve0 commented Mar 21, 2015

I'm doing this:

from PIL import Image
img = Image.open(path)
fp = img.fp
img.load()
fp.closed # False

Expected file pointer to be closed.

System:

  • Windows 7 64bit
  • Python 3.4.1
  • Pillow 2.7.0 (installed via conda)
@aclark4life
Copy link
Member

It's not False, the attribute is missing:

>>> img = Image.open("/Users/alexclark/Downloads/bob 15.jpg")
>>> img.fp.closed
False
>>> img.load()
<PixelAccess object at 0x10664c110>
>>> img.fp.closed
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'closed'

I agree this is wonky.

@arve0
Copy link
Author

arve0 commented Mar 26, 2015

Yes, the file pointer is deleted from img object, but if you copy the reference, you can still see that its there and open.

@aclark4life aclark4life added the Bug Any unexpected behavior, until confirmed feature. label Mar 26, 2015
@aclark4life
Copy link
Member

Ah! OK marked as bug, thanks.

@radarhere
Copy link
Member

I can replicate this on OS X, so it's not just Windows.

I wrote a patch so that the file pointer would close, but I then found that the seek method in GifImagePlugin uses the file pointer after calling load()

@aclark4life aclark4life changed the title Image.load() does not close file pointer on windows 7 Image.load() does not close file pointer Apr 22, 2015
@QuLogic
Copy link
Contributor

QuLogic commented Jul 1, 2015

Same as #835?

@arve0
Copy link
Author

arve0 commented Jul 1, 2015

@QuLogic Seems plausible. Here is the updated line nr:

self.fp = None # might be shared

@hugovk
Copy link
Member

hugovk commented Sep 23, 2017

The code in the first comment now passes:

from PIL import Image
img = Image.open(path)
fp = img.fp
img.load()
fp.closed # was False in original report, but is now True

System:

  • macOS Sierra
  • Python 3.6.0
  • Pillow 2.7.13

See also #835 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anaconda Issues with Anaconda's Pillow Bug Any unexpected behavior, until confirmed feature. Enhancement File Closing
Projects
None yet
Development

No branches or pull requests

6 participants