From 1fbb52cf7d38f8ceee24accdd40fab48fdb47b73 Mon Sep 17 00:00:00 2001 From: Paul Konstantin Gerke Date: Tue, 21 Jan 2025 17:22:46 +0100 Subject: [PATCH] Formatting and improve comment --- panimg/image_builders/tiff.py | 9 ++++++--- panimg/post_processors/tiff_to_dzi.py | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/panimg/image_builders/tiff.py b/panimg/image_builders/tiff.py index 66ef609..ec70ef5 100644 --- a/panimg/image_builders/tiff.py +++ b/panimg/image_builders/tiff.py @@ -2,12 +2,12 @@ import re from collections import defaultdict from collections.abc import Callable, Iterator +from concurrent.futures import ProcessPoolExecutor from dataclasses import dataclass, field from pathlib import Path from tempfile import TemporaryDirectory from typing import DefaultDict from uuid import UUID, uuid4 -from concurrent.futures import ProcessPoolExecutor import tifffile @@ -337,9 +337,12 @@ def _convert( # If this is a globally importable value like "pyvips", # we ship it as string and look it up in _convert_to_tiff - # otherwise we pass the value directly + # otherwise we pass the value directly so that it can be + # used in the subprocess with proper resource isolation if converter in globals().values(): - serialized_converter = [k for k, v in globals().items() if v == converter].pop() + serialized_converter = [ + k for k, v in globals().items() if v == converter + ].pop() else: serialized_converter = converter diff --git a/panimg/post_processors/tiff_to_dzi.py b/panimg/post_processors/tiff_to_dzi.py index ab37c6c..35a41bd 100644 --- a/panimg/post_processors/tiff_to_dzi.py +++ b/panimg/post_processors/tiff_to_dzi.py @@ -1,10 +1,9 @@ import logging +from concurrent.futures import ProcessPoolExecutor from panimg.models import ImageType, PanImgFile, PostProcessorResult from panimg.settings import DZI_TILE_SIZE -from concurrent.futures import ProcessPoolExecutor - try: import pyvips except OSError: @@ -28,7 +27,9 @@ def tiff_to_dzi(*, image_files: set[PanImgFile]) -> PostProcessorResult: if file.image_type == ImageType.TIFF: try: with ProcessPoolExecutor(max_workers=1) as executor: - result = executor.submit(_create_dzi_image, tiff_file=file).result() + result = executor.submit( + _create_dzi_image, tiff_file=file + ).result() except Exception as e: logger.warning(f"Could not create DZI for {file}: {e}") continue