update: jupyter api payload, wire os.environ
This commit is contained in:
@@ -12,6 +12,7 @@ specific concerns:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import socket
|
||||
import subprocess
|
||||
import time
|
||||
@@ -30,6 +31,7 @@ def start_process(
|
||||
cmd: list[str],
|
||||
workspace_path: Path,
|
||||
log_dir: str | Path = "/tmp/process_logs",
|
||||
env: dict[str, str] | None = None,
|
||||
) -> tuple[subprocess.Popen, Path]:
|
||||
"""Launch ``cmd`` as a subprocess and return ``(process, log_file)``.
|
||||
|
||||
@@ -44,6 +46,11 @@ def start_process(
|
||||
start_time = time.strftime("%Y%m%d_%H%M%S")
|
||||
temp_log = log_dir_path / f"process_start_{start_time}.log"
|
||||
|
||||
# 构建合并后的环境变量
|
||||
full_env = os.environ.copy()
|
||||
if env:
|
||||
full_env.update(env)
|
||||
|
||||
with open(temp_log, "a", buffering=1) as log_file:
|
||||
process = subprocess.Popen(
|
||||
cmd,
|
||||
@@ -51,6 +58,7 @@ def start_process(
|
||||
stdout=log_file,
|
||||
stderr=subprocess.STDOUT,
|
||||
start_new_session=True,
|
||||
env=full_env,
|
||||
)
|
||||
|
||||
final_log = log_dir_path / f"process_{process.pid}_{start_time}.log"
|
||||
|
||||
Reference in New Issue
Block a user