diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 67e068b06fa..662afadf43c 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -621,6 +621,8 @@ def close(self) -> None: more information. """ if getattr(self, "map", None): + if sys.platform == "win32" and hasattr(sys, "pypy_version_info"): + self.map.close() self.map: mmap.mmap | None = None # Instead of simply setting to None, we're setting up a diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 1bf8a7e5f21..425dda60bef 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -34,7 +34,6 @@ import logging import os import struct -import sys from typing import IO, TYPE_CHECKING, Any, NamedTuple, cast from . import ExifTags, Image @@ -278,8 +277,6 @@ def load(self) -> Image.core.PixelAccess | None: self.map: mmap.mmap | None = None use_mmap = self.filename and len(self.tile) == 1 - # As of pypy 2.1.0, memory mapping was failing here. - use_mmap = use_mmap and not hasattr(sys, "pypy_version_info") readonly = 0