From eb2ab011986cc93d35b817fd867821e6e205f194 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 1 Jan 2023 18:48:50 +0300 Subject: mqtt_relay_util: exit gracefully on ctrl+c --- src/relay_mqtt_util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/relay_mqtt_util.py b/src/relay_mqtt_util.py index 29a0532..45d2405 100755 --- a/src/relay_mqtt_util.py +++ b/src/relay_mqtt_util.py @@ -39,4 +39,7 @@ if __name__ == '__main__': mqtt_relay = MQTTRelay(devices=MQTTRelayDevice(id=arg.device_id)) mqtt_relay.set_message_callback(on_mqtt_message) mqtt_relay.configure_tls() - mqtt_relay.connect_and_loop() + try: + mqtt_relay.connect_and_loop() + except KeyboardInterrupt: + mqtt_relay.disconnect() -- cgit v1.2.3