From 577fb44914ffbb53f5291b9d37e8a1a9c41a491d Mon Sep 17 00:00:00 2001 From: ILSEON-RYU Date: Sat, 2 May 2026 00:08:53 +0900 Subject: [PATCH] =?UTF-8?q?stdout/stderr=20UTF-8=20=EA=B0=95=EC=A0=9C=20+?= =?UTF-8?q?=20print=20=EB=A9=94=EC=8B=9C=EC=A7=80=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=B9=84-ASCII=20=EA=B8=B0=ED=98=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 배경 이전 자정에 일일 리포트가 발송되지 않은 1차 원인은 긴 sleep 의존(별도 커밋 057335a 에서 폴링 방식으로 전환). 그러나 폴링 적용 후 다시 살펴보니, 새 print 문에서 cp949 (Windows 콘솔 기본 인코딩) 환경에서 em-dash(—)와 right arrow(→) 인코딩 실패로 print 가 예외를 던져 try/except 가 "[일일리포트 스레드 오류]" 로 매번 잡히고 있었음. 자정 발송 로직 자체는 실행되어도 로그가 silent fail 가능성. 향후 동일 문제 차단을 위해 처리. ## 변경 - sys.stdout.reconfigure(encoding="utf-8") + sys.stderr 동일 처리. - PYTHONIOENCODING=utf-8 환경변수도 설정 (subprocess 가 상속받도록). - 로그 메시지의 em-dash -> "--", right arrow -> "->" 로 ASCII 화 (이중 안전장치). Co-Authored-By: Claude Opus 4.7 (1M context) --- app_streamlit.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app_streamlit.py b/app_streamlit.py index afb4a62..2c8ffb0 100644 --- a/app_streamlit.py +++ b/app_streamlit.py @@ -1,7 +1,9 @@ import sys import os -sys.stdout.reconfigure(line_buffering=True) +sys.stdout.reconfigure(line_buffering=True, encoding="utf-8") +sys.stderr.reconfigure(line_buffering=True, encoding="utf-8") os.environ["PYTHONUNBUFFERED"] = "1" +os.environ["PYTHONIOENCODING"] = "utf-8" import time import requests @@ -746,9 +748,9 @@ def _daily_report_loop(): today_str = now_kst.strftime("%Y-%m-%d") if _last_report_date is None: _last_report_date = today_str - print(f"[일일리포트] 스레드 기동 — 다음 자정({today_str} 24:00 KST) 까지 대기") + print(f"[일일리포트] 스레드 기동 -- 다음 자정({today_str} 24:00 KST) 까지 대기") elif _last_report_date != today_str: - print(f"[일일리포트] 자정 통과 감지 → 발송 ({today_str})") + print(f"[일일리포트] 자정 통과 감지 -> 발송 ({today_str})") with _alert_lock: symbol = _alert_symbol send_daily_report(symbol)