diff --git a/ppl2psd.py b/ppl2psd.py index 28078e6..eb452bd 100644 --- a/ppl2psd.py +++ b/ppl2psd.py @@ -739,8 +739,16 @@ def build_psd(layers, width: int, height: int, out_path: str, workers: int, # -------------------------------------------------------------------------- # Main # -------------------------------------------------------------------------- +def _safe_workers(workers: int) -> int: + """Never use every CPU core: leave one for the system, otherwise the + RLE-encoding workers can stall the whole device.""" + available = max(1, (os.cpu_count() or 2) - 1) + return max(1, min(workers, available)) + + def convert(ppl_path: str, out_path: str, preview_path: Optional[str] = None, workers: int = 4, type_layer: bool = False) -> None: + workers = _safe_workers(workers) import tempfile with tempfile.TemporaryDirectory() as tmp: with zipfile.ZipFile(ppl_path) as zf: @@ -884,8 +892,9 @@ def main(): ap.add_argument("input", help="input .ppl file") ap.add_argument("-o", "--output", help="output .psd path") ap.add_argument("--preview", help="also write a downscaled composite PNG") - ap.add_argument("-j", "--workers", type=int, default=4, - help="parallel workers for RLE encoding (default 4)") + ap.add_argument("-j", "--workers", type=int, + default=max(1, (os.cpu_count() or 2) - 1), + help="parallel workers for RLE encoding (default: cores-1)") ap.add_argument("--type-layer", action="store_true", help="convert text layers to editable TypeLayers (TySh) " "instead of rasterized pixels")