diff --git a/src/infuse_iot/util/console.py b/src/infuse_iot/util/console.py index aafe5c2..b17b038 100644 --- a/src/infuse_iot/util/console.py +++ b/src/infuse_iot/util/console.py @@ -2,6 +2,7 @@ import datetime +import threading import colorama @@ -10,6 +11,8 @@ except NotImplementedError: pass +_lock = threading.Lock() + class Console: """Common terminal logging functions""" @@ -56,7 +59,8 @@ def log_rx(data_type, length, prefix=""): def log(timestamp: datetime.datetime, colour, string: str): """Log colourised string to terminal""" ts = timestamp.strftime("%H:%M:%S.%f")[:-3] - print(f"[{ts}]{colour} {string}") + with _lock: + print(f"[{ts}]{colour} {string}") def choose_one(title: str, options: list[str]) -> tuple[int, str]: