From 2ebdf9360b35208ce39e760c1071188294ad63cf Mon Sep 17 00:00:00 2001 From: Liangsheng Yin Date: Tue, 13 Oct 2026 16:31:57 -0700 Subject: [PATCH] [Fix] Work around a CPython fork deadlock in the CPU preprocess pool (#44143) --- .../sglang/srt/multimodal/processors/base_processor.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/sglang/srt/multimodal/processors/base_processor.py b/python/sglang/srt/multimodal/processors/base_processor.py index 4e160a764c..dfb560a919 100644 --- a/python/sglang/srt/multimodal/processors/base_processor.py +++ b/python/sglang/srt/multimodal/processors/base_processor.py @@ -1,6 +1,7 @@ import asyncio import concurrent import concurrent.futures +import concurrent.futures.process import dataclasses import multiprocessing as mp import os @@ -212,6 +213,13 @@ def _tokenizer_of(processor): return processor.tokenizer if hasattr(processor, "tokenizer") else processor +def _forget_parent_executor_wakeups(): + # A forked worker inherits the parent's executor wakeups, whose locks a parent + # thread may hold at fork time; since Python 3.12.8 / 3.13.1 the worker's exit + # hook takes those locks, so the worker would never exit. + concurrent.futures.process._threads_wakeups.clear() + + class BaseMultimodalProcessor(ABC): models = [] gpu_image_decode = True # Enable GPU decoding by default @@ -508,6 +516,7 @@ class BaseMultimodalProcessor(ABC): return concurrent.futures.ProcessPoolExecutor( mp_context=mp.get_context(start_method), max_workers=int(os.environ.get("SGLANG_CPU_WORKERS", os.cpu_count())), + initializer=_forget_parent_executor_wakeups, ) def _replace_broken_cpu_executor(