mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
close the mmap when closing the image #2194
This commit is contained in:
parent
db338ca19a
commit
06b61f4e5b
|
@ -565,6 +565,9 @@ class Image(object):
|
|||
except Exception as msg:
|
||||
logger.debug("Error closing: %s", msg)
|
||||
|
||||
if getattr(self, 'map', None):
|
||||
self.map = None
|
||||
|
||||
# Instead of simply setting to None, we're setting up a
|
||||
# deferred error that will better explain that the core image
|
||||
# object is gone.
|
||||
|
|
|
@ -490,6 +490,7 @@ class TestFileTiffW32(PillowTestCase):
|
|||
tmpfile = self.tempfile("temp.tif")
|
||||
import os
|
||||
|
||||
# this is an mmaped file.
|
||||
with Image.open("Tests/images/uint16_1_4660.tif") as im:
|
||||
im.save(tmpfile)
|
||||
|
||||
|
@ -499,7 +500,12 @@ class TestFileTiffW32(PillowTestCase):
|
|||
self.assertRaises(Exception, lambda: os.remove(tmpfile))
|
||||
im.load()
|
||||
self.assertTrue(fp.closed)
|
||||
# this should not fail, as load should have closed the file.
|
||||
|
||||
# this closes the mmap
|
||||
im.close()
|
||||
|
||||
# this should not fail, as load should have closed the file pointer,
|
||||
# and close should have closed the mmap
|
||||
os.remove(tmpfile)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue
Block a user