update: python script run in python intercept
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user