Skip to content

Do not use DEFAULT_MAX_THREADS when saving AVIF images #8928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/PIL/AvifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,10 @@
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

Check warning on line 60 in src/PIL/AvifImagePlugin.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/AvifImagePlugin.py#L60

Added line #L60 was not covered by tests


class AvifImageFile(ImageFile.ImageFile):
Expand All @@ -81,7 +78,7 @@
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
Expand Down Expand Up @@ -164,7 +161,7 @@
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"
Expand Down
Loading