diff --git a/localite/coil.py b/localite/coil.py index dcca636..be4d485 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" @@ -48,13 +48,16 @@ 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) 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