diff --git a/benchmarks/utils/build_utils.py b/benchmarks/utils/build_utils.py index b4e56b9ad..1fb60657d 100644 --- a/benchmarks/utils/build_utils.py +++ b/benchmarks/utils/build_utils.py @@ -6,6 +6,7 @@ import argparse import contextlib import io +import multiprocessing import os import subprocess import sys @@ -528,7 +529,15 @@ def _chunks(seq: list[str], size: int): ) in_progress: set[str] = set() - with ProcessPoolExecutor(max_workers=max_workers) as ex: + # Use 'spawn' instead of 'fork' to avoid deadlocks when the parent + # process has threads (e.g., from rich.logging.RichHandler). + # With 'fork', child processes inherit copies of locks that may be + # held by threads, causing deadlocks when those locks are needed. + # See: https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods + mp_context = multiprocessing.get_context("spawn") + with ProcessPoolExecutor( + max_workers=max_workers, mp_context=mp_context + ) as ex: futures = {} for base in batch: in_progress.add(base)