This commit is contained in:
Andrew Murray 2025-05-27 10:55:09 -04:00 committed by GitHub
commit 1a17a0c0e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -53,13 +53,10 @@ def _accept(prefix: bytes) -> bool | str:
return False
def _get_default_max_threads() -> int:
if DEFAULT_MAX_THREADS:
return DEFAULT_MAX_THREADS
def _get_max_threads() -> int:
if hasattr(os, "sched_getaffinity"):
return len(os.sched_getaffinity(0))
else:
return os.cpu_count() or 1
return os.cpu_count() or 1
class AvifImageFile(ImageFile.ImageFile):
@ -80,7 +77,7 @@ class AvifImageFile(ImageFile.ImageFile):
self._decoder = _avif.AvifDecoder(
self.fp.read(),
DECODE_CODEC_CHOICE,
_get_default_max_threads(),
DEFAULT_MAX_THREADS or _get_max_threads(),
)
# Get info from decoder
@ -163,7 +160,7 @@ def _save(
duration = info.get("duration", 0)
subsampling = info.get("subsampling", "4:2:0")
speed = info.get("speed", 6)
max_threads = info.get("max_threads", _get_default_max_threads())
max_threads = info.get("max_threads", _get_max_threads())
codec = info.get("codec", "auto")
if codec != "auto" and not _avif.encoder_codec_available(codec):
msg = "Invalid saving codec"