1import threading
2
3def process_image(image_path):
4 # Heavy CPU computation: resize, filter, compress
5 img = load_image(image_path)
6 img = apply_filters(img)
7 return compress(img)
8
9def process_batch(paths, num_threads=8):
10 threads = [threading.Thread(target=process_image, args=(p,))
11 for p in paths]
12 for t in threads: t.start()
13 for t in threads: t.join()
14 # 8 threads is slower than 1 thread on CPU-bound work