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.
This commit is contained in:
8
run.sh
8
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 ..
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user