From 9fe3ce488ed324ffdc1fc49fbef0d549f731945e Mon Sep 17 00:00:00 2001 From: joungmin Date: Sat, 28 Feb 2026 10:42:05 +0900 Subject: [PATCH] fix: auto-restart scanner on crash with Telegram notification Wrap run_scanner() in while True loop so main thread recovers from unhandled exceptions. Sends Telegram alert on crash before restarting. Co-Authored-By: Claude Sonnet 4.6 --- main.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index e962da0..0f1b848 100644 --- a/main.py +++ b/main.py @@ -18,7 +18,7 @@ logging.basicConfig( ) from core.monitor import run_monitor -from core.notify import notify_status +from core.notify import notify_error, notify_status from core.trader import get_positions, restore_positions from daemon.runner import run_scanner @@ -39,6 +39,8 @@ def run_status_reporter(interval: int = STATUS_INTERVAL) -> None: def main() -> None: + logger = logging.getLogger("main") + # 재시작 시 기존 잔고 복원 (이중 매수 방지) restore_positions() @@ -54,8 +56,14 @@ def main() -> None: ) status_thread.start() - # 매수 스캔 루프 (60초 주기, 메인 스레드) - run_scanner() + # 매수 스캔 루프 (60초 주기, 메인 스레드) — 예외 발생 시 Telegram 알림 후 재시작 + while True: + try: + run_scanner() + except Exception as e: + logger.error(f"스캐너 비정상 종료: {e}", exc_info=True) + notify_error(f"스캐너 비정상 종료: {e}\n5초 후 재시작합니다.") + time.sleep(5) if __name__ == "__main__":