Compare commits
2 Commits
f1cf096069
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ab5571cf4 | |||
| fd5c8a9ab4 |
@@ -2,3 +2,7 @@ input/
|
|||||||
output/
|
output/
|
||||||
corrupted/
|
corrupted/
|
||||||
|
|
||||||
|
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
.specstory/
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
# SpecStory project identity file
|
|
||||||
/.project.json
|
|
||||||
# SpecStory explanation file
|
|
||||||
/.what-is-this.md
|
|
||||||
File diff suppressed because it is too large
Load Diff
+20
-1
@@ -7,12 +7,21 @@ Compresses all PNG files in subdirectories with maximum parallelism.
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import platform
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from concurrent.futures import ProcessPoolExecutor, as_completed
|
from concurrent.futures import ProcessPoolExecutor, as_completed
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
# Try to unlock ProcessPoolExecutor on Windows to bypass 61-worker limit
|
||||||
|
try:
|
||||||
|
import unlock_processpool
|
||||||
|
unlock_processpool.please()
|
||||||
|
UNLOCKED = True
|
||||||
|
except ImportError:
|
||||||
|
UNLOCKED = False
|
||||||
|
|
||||||
def compress_png(input_path, output_path, force_bitdepth=None):
|
def compress_png(input_path, output_path, force_bitdepth=None):
|
||||||
"""Compress a single PNG file.
|
"""Compress a single PNG file.
|
||||||
|
|
||||||
@@ -311,7 +320,17 @@ def main():
|
|||||||
print(f"Corrupted files will be moved to: {corrupted_dir}")
|
print(f"Corrupted files will be moved to: {corrupted_dir}")
|
||||||
|
|
||||||
# Use all available CPU cores
|
# Use all available CPU cores
|
||||||
max_workers = multiprocessing.cpu_count()
|
cpu_count = multiprocessing.cpu_count()
|
||||||
|
if platform.system() == 'Windows' and not UNLOCKED:
|
||||||
|
# Windows ProcessPoolExecutor has a maximum of 61 workers (unless unlocked)
|
||||||
|
max_workers = min(cpu_count, 61)
|
||||||
|
if cpu_count > 61:
|
||||||
|
print(f"Detected {cpu_count} CPU threads, but Windows limits ProcessPoolExecutor to 61 workers.")
|
||||||
|
print("Install 'unlock-processpool-win' package to use all cores: pip install unlock-processpool-win")
|
||||||
|
else:
|
||||||
|
max_workers = cpu_count
|
||||||
|
if UNLOCKED:
|
||||||
|
print(f"Using unlock-processpool-win to bypass Windows 61-worker limit")
|
||||||
print(f"Using {max_workers} worker processes for compression...")
|
print(f"Using {max_workers} worker processes for compression...")
|
||||||
print("-" * 80)
|
print("-" * 80)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user