From 6c6e7e6500ec5b79b656d35953eb6e29fe0b91ed Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Tue, 11 Aug 2026 16:20:40 +0800 Subject: [PATCH] update: python script run in python intercept --- schedule/src/schedule/execution.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/schedule/src/schedule/execution.py b/schedule/src/schedule/execution.py index 088e4e9..7d9a29f 100644 --- a/schedule/src/schedule/execution.py +++ b/schedule/src/schedule/execution.py @@ -13,6 +13,20 @@ from loguru import logger 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) class ExecutionResult: status: str @@ -135,8 +149,14 @@ async def _execute_python( timeout_seconds: int, python_version: str = "3.12", ) -> ExecutionResult: - # NOTE: The worker process runs a single interpreter, so .py scripts - # continue to use sys.executable. Switching interpreters is future work. + # NOTE: .py scripts run inside the per-version venv installed in the + # 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( "python exec start: artifact={} timeout={}s version={} args={}", artifact.name, @@ -145,7 +165,7 @@ async def _execute_python( len(arguments), ) process = await asyncio.create_subprocess_exec( - sys.executable, + python_bin, str(artifact), *arguments, cwd=str(artifact.parent),