From 0fdaff09153e3b36da58c491e8d38c40784f9f21 Mon Sep 17 00:00:00 2001 From: jfs Date: Mon, 22 Jul 2024 15:50:07 +0300 Subject: [PATCH] fix: postpone starting rx loop until all attributes are set It fixes: `AttributeError: 'IMU' object has no attribute 'subscribers'` --- witmotion/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/witmotion/__init__.py b/witmotion/__init__.py index 8030375..bbcb61a 100644 --- a/witmotion/__init__.py +++ b/witmotion/__init__.py @@ -70,8 +70,6 @@ def __init__(self, path: str = "/dev/ttyUSB0", baudrate: int = 9600): # self.ser.write(b"\x00" * 5) self.should_exit = False - self.rxthread = Thread(target=self._rxloop) - self.rxthread.start() self.subscribers = defaultdict(list) # State we have received @@ -85,6 +83,9 @@ def __init__(self, path: str = "/dev/ttyUSB0", baudrate: int = 9600): self.last_mag = None self.last_q = None + self.rxthread = Thread(target=self._rxloop) + self.rxthread.start() + def close(self) -> None: """ Close IMU connection and stop background monitoring thread..