parameters: (self)
docstring: Reader loop
docstring_summary: Reader loop
docstring_tokens: Reader loop
function: def run(self):
          """Reader loop"""
          if not hasattr(self.serial, 'cancel_read'):
              self.serial.timeout = 1
          self.protocol = self.protocol_factory()
          try:
              self.protocol.connection_made(self)
          except Exception as e:
              self.alive = False
              self.protocol.connection_lost(e)
              self._connection_made.set()
              return
          error = None
          self._connection_made.set()
          while self.alive and self.serial.is_open:
              try:
                  # read all that is there or wait for one byte (blocking)
                  data = self.serial.read(self.serial.in_waiting or 1)
              except serial.SerialException as e:
                  # probably some I/O problem such as disconnected USB serial
                  # adapters -> exit
                  error = e
                  break
              else:
                  if data:
                      # make a separated try-except for called used code
                      try:
                          self.protocol.data_received(data)
                      except Exception as e:
                          error = e
                          break
          self.alive = False
          self.protocol.connection_lost(error)
          self.protocol = None
function_tokens: def run ( self ) : if not hasattr ( self . serial , 'cancel_read' ) : self . serial . timeout = 1 self . protocol = self . protocol_factory ( ) try : self . protocol . connection_made ( self ) except Exception as e : self . alive = False self . protocol . connection_lost ( e ) self . _connection_made . set ( ) return error = None self . _connection_made . set ( ) while self . alive and self . serial . is_open : try : # read all that is there or wait for one byte (blocking) data = self . serial . read ( self . serial . in_waiting or 1 ) except serial . SerialException as e : # probably some I/O problem such as disconnected USB serial # adapters -> exit error = e break else : if data : # make a separated try-except for called used code try : self . protocol . data_received ( data ) except Exception as e : error = e break self . alive = False self . protocol . connection_lost ( error ) self . protocol = None