Cap workers at cores-1 so encoding never stalls the system

This commit is contained in:
AskaEth committed 2026-08-28 09:11:24 +08:00
1 parent c9c1b6d238
commit 62da58f93d
1 file changed
+11 -2
+11 -2
View File
@@ -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")