File tree Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -619,8 +619,6 @@ def __exit__(self, *args):
619
619
620
620
def close (self ) -> None :
621
621
"""
622
- Closes the file pointer, if possible.
623
-
624
622
This operation will destroy the image core and release its memory.
625
623
The image data will be unusable afterward.
626
624
@@ -629,13 +627,6 @@ def close(self) -> None:
629
627
:py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for
630
628
more information.
631
629
"""
632
- if hasattr (self , "fp" ):
633
- try :
634
- self ._close_fp ()
635
- self .fp = None
636
- except Exception as msg :
637
- logger .debug ("Error closing: %s" , msg )
638
-
639
630
if getattr (self , "map" , None ):
640
631
self .map : mmap .mmap | None = None
641
632
Original file line number Diff line number Diff line change 31
31
import abc
32
32
import io
33
33
import itertools
34
+ import logging
34
35
import os
35
36
import struct
36
37
import sys
43
44
if TYPE_CHECKING :
44
45
from ._typing import StrOrBytesPath
45
46
47
+ logger = logging .getLogger (__name__ )
48
+
46
49
MAXBLOCK = 65536
47
50
48
51
SAFEBLOCK = 1024 * 1024
@@ -163,6 +166,26 @@ def __init__(
163
166
def _open (self ) -> None :
164
167
pass
165
168
169
+ def close (self ) -> None :
170
+ """
171
+ Closes the file pointer, if possible.
172
+
173
+ This operation will destroy the image core and release its memory.
174
+ The image data will be unusable afterward.
175
+
176
+ This function is required to close images that have multiple frames or
177
+ have not had their file read and closed by the
178
+ :py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for
179
+ more information.
180
+ """
181
+ try :
182
+ self ._close_fp ()
183
+ self .fp = None
184
+ except Exception as msg :
185
+ logger .debug ("Error closing: %s" , msg )
186
+
187
+ super ().close ()
188
+
166
189
def get_child_images (self ) -> list [ImageFile ]:
167
190
child_images = []
168
191
exif = self .getexif ()
You can’t perform that action at this time.
0 commit comments