@@ -93,18 +93,15 @@ def _disconnected(self) -> None:
9393
9494 logger .debug ("Closing our port" )
9595 # pylint: disable=E0203
96- if hasattr ( self , "stream" ) and self .stream is not None and getattr ( self . stream , "is_open" , False ) :
96+ if not self .stream is None :
9797 # pylint: disable=E0203
98- try :
99- self .stream .close ()
100- except Exception as e :
101- logger .debug (f"Exception during close: { e } " )
98+ self .stream .close ()
10299 # pylint: disable=W0201
103100 self .stream = None
104101
105102 def _writeBytes (self , b : bytes ) -> None :
106103 """Write an array of bytes to our stream and flush"""
107- if self .stream and self . stream is not None and getattr ( self . stream , "is_open" , False ): # ignore writes when stream is closed
104+ if self .stream : # ignore writes when stream is closed
108105 self .stream .write (b )
109106 self .stream .flush ()
110107 # win11 might need a bit more time, too
@@ -116,7 +113,7 @@ def _writeBytes(self, b: bytes) -> None:
116113
117114 def _readBytes (self , length ) -> Optional [bytes ]:
118115 """Read an array of bytes from our stream"""
119- if self .stream and self . stream is not None and getattr ( self . stream , "is_open" , False ) :
116+ if self .stream :
120117 return self .stream .read (length )
121118 else :
122119 return None
@@ -226,12 +223,10 @@ def __reader(self) -> None:
226223 logger .error (
227224 f"Unexpected OSError, terminating meshtastic reader... { ex } "
228225 )
229- traceback .print_exc ()
230226 except Exception as ex :
231227 logger .error (
232228 f"Unexpected exception, terminating meshtastic reader... { ex } "
233229 )
234- traceback .print_exc ()
235230 finally :
236231 logger .debug ("reader is exiting" )
237232 self ._disconnected ()
0 commit comments