From bce83ac800dd70c8b49fff9662a2352b2a388a0b Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Sun, 30 Mar 2025 03:36:36 +1100 Subject: [PATCH] Enable mmap on PyPy (#8840) --- src/PIL/Image.py | 2 ++ src/PIL/ImageFile.py | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 67e068b06..662afadf4 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -621,6 +621,8 @@ class Image: 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 f5b72ee0d..a7848c369 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -34,7 +34,6 @@ import itertools 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 @@ class ImageFile(Image.Image): 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