mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-06 12:53:12 +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:
|
except Exception as msg:
|
||||||
logger.debug("Error closing: %s", 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
|
# Instead of simply setting to None, we're setting up a
|
||||||
# deferred error that will better explain that the core image
|
# deferred error that will better explain that the core image
|
||||||
# object is gone.
|
# object is gone.
|
||||||
|
|
|
@ -490,6 +490,7 @@ class TestFileTiffW32(PillowTestCase):
|
||||||
tmpfile = self.tempfile("temp.tif")
|
tmpfile = self.tempfile("temp.tif")
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
# this is an mmaped file.
|
||||||
with Image.open("Tests/images/uint16_1_4660.tif") as im:
|
with Image.open("Tests/images/uint16_1_4660.tif") as im:
|
||||||
im.save(tmpfile)
|
im.save(tmpfile)
|
||||||
|
|
||||||
|
@ -499,7 +500,12 @@ class TestFileTiffW32(PillowTestCase):
|
||||||
self.assertRaises(Exception, lambda: os.remove(tmpfile))
|
self.assertRaises(Exception, lambda: os.remove(tmpfile))
|
||||||
im.load()
|
im.load()
|
||||||
self.assertTrue(fp.closed)
|
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)
|
os.remove(tmpfile)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user