From 057335a1734d4d44a0bac12438e7b31e8a37b996 Mon Sep 17 00:00:00 2001 From: ILSEON-RYU Date: Sat, 2 May 2026 00:06:57 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=BC=EC=9D=BC=20=EB=A6=AC=ED=8F=AC?= =?UTF-8?q?=ED=8A=B8=20=EC=8A=A4=EB=A0=88=EB=93=9C=EB=A5=BC=20=EA=B8=B4=20?= =?UTF-8?q?sleep=20->=2060s=20=ED=8F=B4=EB=A7=81=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20+=20=EB=A1=9C?= =?UTF-8?q?=EA=B9=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 문제 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) --- app_streamlit.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app_streamlit.py b/app_streamlit.py index d46faae..afb4a62 100644 --- a/app_streamlit.py +++ b/app_streamlit.py @@ -736,17 +736,26 @@ def send_daily_report(symbol="BTCUSDT"): lines.append(f"합계: {passed_all}T {failed_all}F (승률 {rate:.2f}%)") send_telegram("\n".join(lines)) +_last_report_date = None + def _daily_report_loop(): + global _last_report_date 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: - with _alert_lock: - symbol = _alert_symbol - send_daily_report(symbol) + 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: + symbol = _alert_symbol + send_daily_report(symbol) + _last_report_date = today_str except Exception as e: print(f"[일일리포트 스레드 오류] {e}") + time.sleep(60) # ────────────────────────────────────────────── # 메인 UI