From 7aa3bd52ef1618ab005a06eb199de96a930a03ed Mon Sep 17 00:00:00 2001 From: busya Date: Wed, 27 May 2026 10:19:16 +0300 Subject: [PATCH] fix: add PYTHONUNBUFFERED=1 to run.sh to prevent stderr buffering Without PYTHONUNBUFFERED, when stderr is piped through '2>&1 | sed', Python fully buffers stderr output. JSON log lines are small and never fill the buffer, so they never appear in real time (or at all for sporadic HTTP request logs). Startup logs appeared because the buffer flushed on process exit during Alembic migration. Also kept --reload removed as it breaks stderr capture from child process. --- run.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/run.sh b/run.sh index d65fa970..bd2a6751 100755 --- a/run.sh +++ b/run.sh @@ -204,11 +204,13 @@ start_backend() { if [ -f ".env" ]; then uvicorn_env_args=(--env-file .env) fi - # Use a subshell to prefix output - # NOTE: --reload breaks stderr capture (subprocess child loses the 2>&1 pipe). + # PYTHONUNBUFFERED=1 prevents stderr buffering when piped through sed. + # Without it, JSON logs from superset_tools_app get stuck in the buffer + # and never appear in real time (or at all, for small log lines). + # NOTE: --reload also breaks stderr capture (subprocess child loses the pipe). # For hot-reload during development, run uvicorn directly instead: # cd backend && source .venv/bin/activate && uvicorn src.app:app --reload --port 8000 - python3 -m uvicorn src.app:app --port "$BACKEND_PORT" "${uvicorn_env_args[@]}" 2>&1 | sed "s/^/$(echo -e '\033[0;34m[Backend]\033[0m ') /" & + PYTHONUNBUFFERED=1 python3 -m uvicorn src.app:app --port "$BACKEND_PORT" "${uvicorn_env_args[@]}" 2>&1 | sed "s/^/$(echo -e '\033[0;34m[Backend]\033[0m ') /" & BACKEND_PID=$! cd .. }