From 11a4c760d76521f3ab1c4df3a730d82e4ea976ff Mon Sep 17 00:00:00 2001 From: Philip Trauner Date: Mon, 24 Apr 2017 14:25:17 +0300 Subject: [PATCH] Wait for server to become avaliable --- Wallaby/Wallaby.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Wallaby/Wallaby.py b/Wallaby/Wallaby.py index ca28e9c..7c85393 100644 --- a/Wallaby/Wallaby.py +++ b/Wallaby/Wallaby.py @@ -347,14 +347,20 @@ except (IOError, ExceptionInConfigError): try: - ws = Handler(config.server_address) - # setup has to be called before the connection is established - ws.setup({"subscribe" : Subscribe(), "sensor" : Sensor(), + while 1: + ws = Handler(config.server_address) + # setup has to be called before the connection is established + ws.setup({"subscribe" : Subscribe(), "sensor" : Sensor(), "identify" : Identify(), "whoami" : WhoAmI(), "stop_programs" : StopPrograms(), "shutdown" : Shutdown(), "reboot" : Reboot(), "output" : Output()}, debug=False) - ws.connect() + try: + ws.connect() + break + except ConnectionRefusedError: + Logging.warning("Server not running... Retrying in 5s") + time.sleep(5) ws.run_forever() except KeyboardInterrupt: ws.close()