update: python script run in python intercept

This commit is contained in:
tao.chen
2026-08-11 16:20:40 +08:00
parent ec9effc254
commit 6c6e7e6500
+23 -3
View File
@@ -13,6 +13,20 @@ from loguru import logger
MAX_LOG_BYTES = 4 * 1024 * 1024 MAX_LOG_BYTES = 4 * 1024 * 1024
_PYTHON_VENV_BIN: dict[str, str] = {
"3.8": "/opt/venv/python3.8/bin/python",
"3.10": "/opt/venv/python3.10/bin/python",
"3.12": "/opt/venv/python3.12/bin/python",
}
def _resolve_python(version: str) -> str:
try:
return _PYTHON_VENV_BIN[version]
except KeyError:
raise ValueError(f"unsupported python_version: {version}")
@dataclass(frozen=True) @dataclass(frozen=True)
class ExecutionResult: class ExecutionResult:
status: str status: str
@@ -135,8 +149,14 @@ async def _execute_python(
timeout_seconds: int, timeout_seconds: int,
python_version: str = "3.12", python_version: str = "3.12",
) -> ExecutionResult: ) -> ExecutionResult:
# NOTE: The worker process runs a single interpreter, so .py scripts # NOTE: .py scripts run inside the per-version venv installed in the
# continue to use sys.executable. Switching interpreters is future work. # schedule image, e.g. /opt/venv/python3.12/bin/python for version 3.12.
python_bin = _resolve_python(python_version)
logger.debug(
"python exec interpreter: artifact={} interpreter={}",
artifact.name,
python_bin,
)
logger.debug( logger.debug(
"python exec start: artifact={} timeout={}s version={} args={}", "python exec start: artifact={} timeout={}s version={} args={}",
artifact.name, artifact.name,
@@ -145,7 +165,7 @@ async def _execute_python(
len(arguments), len(arguments),
) )
process = await asyncio.create_subprocess_exec( process = await asyncio.create_subprocess_exec(
sys.executable, python_bin,
str(artifact), str(artifact),
*arguments, *arguments,
cwd=str(artifact.parent), cwd=str(artifact.parent),