일일 리포트 스레드를 긴 sleep -> 60s 폴링 방식으로 변경 + 로깅
## 문제 2026-05-02 00:00 KST 자정에 일일 신호 통계 알림이 발송되지 않았음. 원인 추정: time.sleep(약 2.77h) 같은 긴 sleep 이 Streamlit 의 메인 루프와 함께 돌면서 데몬 스레드가 깨어나지 않았거나, 깨어났더라도 silent 하게 중단됨. send_daily_report 함수 자체를 직접 호출하면 정상 동작 확인. ## 변경 - 짧은 sleep(60s) 폴링 루프로 변경. - 매 폴링마다 KST 날짜를 확인 → 마지막 발송 날짜와 다르면(=자정 통과) 발송. - 자정 통과 후 최대 60초 이내 발송 보장. - 첫 폴링에서는 _last_report_date 를 오늘 날짜로 초기화 (재기동 직후 즉시 발송되어 사용자가 혼란해지는 것 방지). - 발송 / 기동 / 오류 시 print 로그 남김. 기존 send_daily_report 함수 자체는 변경 없음. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+12
-3
@@ -736,17 +736,26 @@ def send_daily_report(symbol="BTCUSDT"):
|
|||||||
lines.append(f"합계: {passed_all}T {failed_all}F (승률 {rate:.2f}%)")
|
lines.append(f"합계: {passed_all}T {failed_all}F (승률 {rate:.2f}%)")
|
||||||
send_telegram("\n".join(lines))
|
send_telegram("\n".join(lines))
|
||||||
|
|
||||||
|
_last_report_date = None
|
||||||
|
|
||||||
def _daily_report_loop():
|
def _daily_report_loop():
|
||||||
|
global _last_report_date
|
||||||
while True:
|
while True:
|
||||||
now = datetime.now(timezone.utc) + KST
|
|
||||||
next_mid = (now + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0)
|
|
||||||
time.sleep(max(60, (next_mid - now).total_seconds()))
|
|
||||||
try:
|
try:
|
||||||
|
now_kst = (datetime.now(timezone.utc) + KST).replace(tzinfo=None)
|
||||||
|
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) 까지 대기")
|
||||||
|
elif _last_report_date != today_str:
|
||||||
|
print(f"[일일리포트] 자정 통과 감지 → 발송 ({today_str})")
|
||||||
with _alert_lock:
|
with _alert_lock:
|
||||||
symbol = _alert_symbol
|
symbol = _alert_symbol
|
||||||
send_daily_report(symbol)
|
send_daily_report(symbol)
|
||||||
|
_last_report_date = today_str
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[일일리포트 스레드 오류] {e}")
|
print(f"[일일리포트 스레드 오류] {e}")
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
# ──────────────────────────────────────────────
|
# ──────────────────────────────────────────────
|
||||||
# 메인 UI
|
# 메인 UI
|
||||||
|
|||||||
Reference in New Issue
Block a user