Processes for CPU-bound work

Because of the GIL, threads don't speed up pure Python computing. Processes do. Each process is a separate Python with its own GIL, so they run on separate cores.

ProcessPoolExecutor has the same interface as the thread pool:

from concurrent.futures import ProcessPoolExecutor

def count_primes(limit: int) -> int: ...

if __name__ == "__main__":       # required: workers import this file
    with ProcessPoolExecutor() as pool:
        counts = list(pool.map(count_primes, [50_000] * 4))

The cost: arguments and results are copied between processes (pickled), and starting a process takes time. So send a few big chunks of work, not a million tiny ones. multiprocessing.Pool is the older API for the same thing.

Processes don't run in the browser. The program splits the work into chunks the way you would for a pool, then runs them one by one. Run it, then change the chunk sizes and check the total stays the same.