Avoid creating log files when no serial device is connected
This commit is contained in:
@@ -158,7 +158,6 @@ class SerialBridge(threading.Thread):
|
|||||||
self._log_file.write(f"{ts} {line}\n")
|
self._log_file.write(f"{ts} {line}\n")
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self._open_log()
|
|
||||||
try:
|
try:
|
||||||
while not self._stop_event.is_set():
|
while not self._stop_event.is_set():
|
||||||
if self._serial is None:
|
if self._serial is None:
|
||||||
@@ -180,6 +179,7 @@ class SerialBridge(threading.Thread):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.broadcaster.publish(f"[bridge] disconnected: {exc}")
|
self.broadcaster.publish(f"[bridge] disconnected: {exc}")
|
||||||
self._close_serial()
|
self._close_serial()
|
||||||
|
self._close_log()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
finally:
|
finally:
|
||||||
self._close_serial()
|
self._close_serial()
|
||||||
|
|||||||
Reference in New Issue
Block a user