Skip to content

Commit 92f0ae6

Browse files
mikasenghaasclaude
andauthored
use spawn multiprocessing method for sidecar env server (#917)
* Use spawn multiprocessing method for sidecar env server Switch from the default fork method to spawn when creating the env server subprocess. Fork inherits all file descriptors from the parent, which means multiple env server subprocesses can share sockets and other fds, leading to hangs. Spawn starts a fresh interpreter and avoids this class of issues. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * use mp --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2b9ce72 commit 92f0ae6

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

verifiers/envs/environment.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from collections.abc import Mapping
1515
from concurrent.futures import ThreadPoolExecutor
1616
from copy import deepcopy
17-
from multiprocessing import Process
17+
import multiprocessing as mp
18+
from multiprocessing.process import BaseProcess
1819
from pathlib import Path
1920
from typing import (
2021
TYPE_CHECKING,
@@ -146,7 +147,7 @@ def __init__(
146147
self.set_score_rollouts(score_rollouts)
147148

148149
self.env_client: EnvClient | None = None
149-
self.env_server_process: Process | None = None
150+
self.env_server_process: BaseProcess | None = None
150151

151152
# Dataset sources (builders) and built datasets
152153
# Use get_dataset()/get_eval_dataset() for access; build_dataset() to trigger build
@@ -1268,7 +1269,10 @@ async def start_server(
12681269
depending on it directly.
12691270
"""
12701271
address = address or f"tcp://127.0.0.1:{get_free_port()}"
1271-
self.env_server_process = Process(
1272+
# Use spawn to avoid inheriting file descriptors (e.g. sockets) from
1273+
# the parent process, which has caused hangs when multiple env server
1274+
# subprocesses share the same fds.
1275+
self.env_server_process = mp.get_context("spawn").Process(
12721276
target=ZMQEnvServer.run_server,
12731277
args=(
12741278
self.env_id,

0 commit comments

Comments
 (0)