From b4c3ec57fff0e235ad2c5e369f86e02fd2329a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Thu, 16 Dec 2021 13:37:34 +0100 Subject: [PATCH 1/2] Add timeout when receiver is not found after 5 seconds --- localite/coil.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/localite/coil.py b/localite/coil.py index dcca636..5257e3f 100644 --- a/localite/coil.py +++ b/localite/coil.py @@ -6,7 +6,7 @@ from localite.flow.mrk import Receiver from typing import Tuple, Dict, Any, Union import json -from time import sleep +import time def pythonize_values(v: str) -> Union[bool, None, str]: "pythonize a dictionaries values" @@ -54,7 +54,10 @@ def __init__(self, coil: int = 0, address: Tuple[str, int] = ("127.0.0.1", 6667) self._push_loc = partial(push, fmt="loc", host=host, port=port) self.receiver = Receiver(name="localite_marker") self.receiver.start() + start_receiver_time = time.time() while not self.receiver.is_running.is_set(): + if time.time() > start_receiver_time + timeout: + raise ConnectionError("Could not connect to localite flow") pass self.id = coil From e791a428af60b311e7efa501b32953baebd3e8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Thu, 16 Dec 2021 13:42:14 +0100 Subject: [PATCH 2/2] Add timeout default --- localite/coil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localite/coil.py b/localite/coil.py index 5257e3f..be4d485 100644 --- a/localite/coil.py +++ b/localite/coil.py @@ -48,7 +48,7 @@ class Coil: """ - def __init__(self, coil: int = 0, address: Tuple[str, int] = ("127.0.0.1", 6667)): + def __init__(self, coil: int = 0, address: Tuple[str, int] = ("127.0.0.1", 6667), timeout=10): host, port = address self._push_mrk = partial(push, fmt="mrk", host=host, port=port) self._push_loc = partial(push, fmt="loc", host=host, port=port)