added keyboard interupt handling

This commit is contained in:
2026-04-17 02:21:35 +05:30
parent c4dd0a138c
commit ac931feb47

View File

@@ -28,7 +28,8 @@ ntfy_token = os.environ['NTFY_Token']
device_name = os.environ['device_name']
shutdown_timer = int(os.environ['shutdown_timer'])
with serial.Serial(device_name, 115200, timeout=1) as ser:
try:
with serial.Serial(device_name, 115200, timeout=1) as ser:
inverter_offline_counter = 0
while True:
if ser.readline().decode().strip() == "0":
@@ -48,3 +49,6 @@ with serial.Serial(device_name, 115200, timeout=1) as ser:
}
)
os.system("shutdown now")
except KeyboardInterrupt:
logger.info("Exiting gracefully")
exit()