tao-shen Claude Opus 4.6 commited on
Commit
59be1b8
Β·
1 Parent(s): 9161deb

fix: switch all log output from tee (pipe-buffered) to direct stderr

Browse files

HF's runtime log SSE captures stderr unbuffered. Using `echo | tee`
creates a pipe that block-buffers when stdout is not a TTY in Docker,
preventing real-time delivery to the SSE stream. Switch to:
- bash: echo >&2 (direct, unbuffered) + echo >> file
- python: print(file=sys.stderr, flush=True)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

scripts/entrypoint.sh CHANGED
@@ -11,7 +11,8 @@ LOGFILE="/var/log/huggingrun.log"
11
  touch "$LOGFILE"
12
 
13
  log() {
14
- echo "$@" | tee -a "$LOGFILE"
 
15
  }
16
 
17
  log "========================================"
 
11
  touch "$LOGFILE"
12
 
13
  log() {
14
+ echo "$@" >> "$LOGFILE"
15
+ echo "$@" >&2
16
  }
17
 
18
  log "========================================"
ubuntu-server/git_sync_daemon.py CHANGED
@@ -55,7 +55,7 @@ LOGFILE = "/var/log/huggingrun.log"
55
  def log(msg):
56
  ts = time.strftime("%H:%M:%S", time.gmtime())
57
  line = f"[sync {ts}] {msg}"
58
- print(line, flush=True)
59
  try:
60
  with open(LOGFILE, "a") as f:
61
  f.write(line + "\n")
 
55
  def log(msg):
56
  ts = time.strftime("%H:%M:%S", time.gmtime())
57
  line = f"[sync {ts}] {msg}"
58
+ print(line, file=sys.stderr, flush=True)
59
  try:
60
  with open(LOGFILE, "a") as f:
61
  f.write(line + "\n")
ubuntu-server/start-server.sh CHANGED
@@ -10,10 +10,11 @@ LOGFILE="/var/log/huggingrun.log"
10
  export SSH_PORT="${SSH_PORT:-2222}"
11
  export TTYD_PORT="${TTYD_PORT:-7681}"
12
 
13
- # Log to file + stdout (HF captures container stdout/stderr)
14
  log() {
15
  local msg="$*"
16
- echo "$msg" | tee -a "$LOGFILE"
 
17
  }
18
 
19
  # ── Start nginx FIRST so HF sees port 7860 ──────────────────────
 
10
  export SSH_PORT="${SSH_PORT:-2222}"
11
  export TTYD_PORT="${TTYD_PORT:-7681}"
12
 
13
+ # Log to file + stderr (HF captures container stderr; no pipe = no buffering)
14
  log() {
15
  local msg="$*"
16
+ echo "$msg" >> "$LOGFILE"
17
+ echo "$msg" >&2
18
  }
19
 
20
  # ── Start nginx FIRST so HF sees port 7860 ──────────────────────