Skip to content

Commit f15a0bd

Browse files
committed
Add more exception logging, fix some additional stream read/write issues
1 parent 0906fc6 commit f15a0bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

meshtastic/stream_interface.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _disconnected(self) -> None:
104104

105105
def _writeBytes(self, b: bytes) -> None:
106106
"""Write an array of bytes to our stream and flush"""
107-
if self.stream: # ignore writes when stream is closed
107+
if self.stream and self.stream is not None and getattr(self.stream, "is_open", False): # ignore writes when stream is closed
108108
self.stream.write(b)
109109
self.stream.flush()
110110
# win11 might need a bit more time, too
@@ -116,7 +116,7 @@ def _writeBytes(self, b: bytes) -> None:
116116

117117
def _readBytes(self, length) -> Optional[bytes]:
118118
"""Read an array of bytes from our stream"""
119-
if self.stream:
119+
if self.stream and self.stream is not None and getattr(self.stream, "is_open", False):
120120
return self.stream.read(length)
121121
else:
122122
return None
@@ -226,10 +226,12 @@ def __reader(self) -> None:
226226
logger.error(
227227
f"Unexpected OSError, terminating meshtastic reader... {ex}"
228228
)
229+
traceback.print_exc()
229230
except Exception as ex:
230231
logger.error(
231232
f"Unexpected exception, terminating meshtastic reader... {ex}"
232233
)
234+
traceback.print_exc()
233235
finally:
234236
logger.debug("reader is exiting")
235237
self._disconnected()

0 commit comments

Comments
 (0)