mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-14 18:17:44 +00:00
[CK Tools] Auto-enable unbuffered output for Python commands (#4265)
ck-docker exec and ck-exec now automatically detect Python commands and set PYTHONUNBUFFERED=1 to enable live output streaming. This eliminates the need to manually set the environment variable when running Python scripts that print progress updates. The detection matches python, python3, or any .py file argument. This helps in watching live terminal output when a python script is running inside the container. --- 🔁 Imported from [ROCm/composable_kernel#3694](https://github.com/ROCm/composable_kernel/pull/3694) 🧑💻 Originally authored by @AviralGoelAMD Co-authored-by: AviralGoelAMD <aviral.goel@amd.com> Co-authored-by: Claude (claude-opus-4.5) <noreply@anthropic.com> Co-authored-by: systems-assistant[bot] <systems-assistant[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9ecc13eecd
commit
87fd831d43
@@ -112,6 +112,19 @@ cmd_exec() {
|
||||
local docker_flags=()
|
||||
[ -t 0 ] && [ -t 1 ] && docker_flags+=("-it")
|
||||
|
||||
# Auto-detect Python commands and enable unbuffered output for live streaming
|
||||
local is_python=false
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" == "python" || "$arg" == "python3" || "$arg" == *.py ]]; then
|
||||
is_python=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$is_python" = true ]; then
|
||||
docker_flags+=("-e" "PYTHONUNBUFFERED=1")
|
||||
fi
|
||||
|
||||
docker exec "${docker_flags[@]}" "${CONTAINER_NAME}" "$@"
|
||||
}
|
||||
|
||||
|
||||
@@ -103,9 +103,18 @@ for arg in "${command_args[@]}"; do
|
||||
cmd_string="${cmd_string} $(printf '%q' "$arg")"
|
||||
done
|
||||
|
||||
# Auto-detect Python commands and enable unbuffered output for live streaming
|
||||
env_flags=""
|
||||
for arg in "${command_args[@]}"; do
|
||||
if [[ "$arg" == "python" || "$arg" == "python3" || "$arg" == *.py ]]; then
|
||||
env_flags="-e PYTHONUNBUFFERED=1"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Execute command
|
||||
if [ "$interactive" = true ]; then
|
||||
docker exec -it -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}"
|
||||
docker exec -it ${env_flags} -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}"
|
||||
else
|
||||
docker exec -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}"
|
||||
docker exec ${env_flags} -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user