stuck in retrying backend loop, fix issue #652 (#862)

* maybe solution to issue #652

* formatting, when precommit merge?

* Update lnbits/app.py

* Update lnbits/app.py

Co-authored-by: dni <dni.khr@gmail.com>
Co-authored-by: calle <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
dni ⚡
2022-08-13 14:46:47 +02:00
committed by GitHub
parent 28661903b6
commit 034813a1ab

View File

@ -1,6 +1,7 @@
import asyncio import asyncio
import importlib import importlib
import logging import logging
import signal
import sys import sys
import traceback import traceback
import warnings import warnings
@ -101,7 +102,15 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
def check_funding_source(app: FastAPI) -> None: def check_funding_source(app: FastAPI) -> None:
@app.on_event("startup") @app.on_event("startup")
async def check_wallet_status(): async def check_wallet_status():
original_sigint_handler = signal.getsignal(signal.SIGINT)
def signal_handler(signal, frame):
logger.debug(f"SIGINT received, terminating LNbits.")
sys.exit(1)
signal.signal(signal.SIGINT, signal_handler)
while True: while True:
try:
error_message, balance = await WALLET.status() error_message, balance = await WALLET.status()
if not error_message: if not error_message:
break break
@ -111,6 +120,9 @@ def check_funding_source(app: FastAPI) -> None:
) )
logger.info("Retrying connection to backend in 5 seconds...") logger.info("Retrying connection to backend in 5 seconds...")
await asyncio.sleep(5) await asyncio.sleep(5)
except:
pass
signal.signal(signal.SIGINT, original_sigint_handler)
logger.info( logger.info(
f"✔️ Backend {WALLET.__class__.__name__} connected and with a balance of {balance} msat." f"✔️ Backend {WALLET.__class__.__name__} connected and with a balance of {balance} msat."
) )