Explore Library
Code Quiz

Parallelizing CPU-bound prime checks

A CPU-bound prime checker uses process-based parallelism but crashes or spawns endlessly at import.

Codepython
from concurrent.futures import ProcessPoolExecutor
import math

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, math.isqrt(n) + 1):
        if n % i == 0:
            return False
    return True

numbers = [112272535095293, 112582705942171, 115280095190773]

executor = ProcessPoolExecutor()
results = list(executor.map(is_prime, numbers))
print(results)

This code aims to bypass the GIL for CPU-bound work using processes. What is the bug that breaks it on spawn-based platforms (Windows, and macOS by default)?