From 388218f9df4e62f9dfcfcf164ed669f4b57c3f37 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 27 Feb 2020 18:43:58 +0100 Subject: [PATCH] implement a reconnection loop for direwolf, ref #60 --- owrx/kiss.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/owrx/kiss.py b/owrx/kiss.py index d47fa4d..374cc07 100644 --- a/owrx/kiss.py +++ b/owrx/kiss.py @@ -69,9 +69,19 @@ class KissClient(object): pass def __init__(self, port): - time.sleep(1) - self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.socket.connect(("localhost", port)) + delay = .5 + retries = 0 + while True: + try: + self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.socket.connect(("localhost", port)) + break + except ConnectionError: + if retries > 20: + logger.error("maximum number of connection attempts reached. did direwolf start up correctly?") + raise + retries += 1 + time.sleep(delay) def read(self): return self.socket.recv(1)