code: def _get_input(self, length):
          
          self._buffer_lock.acquire()
          try:
              if length == -1:
                  actualLength = len(self._buffer)
              else:
                  actualLength = min(length, len(self._buffer))
              if actualLength:
                  data = self._buffer[:actualLength]
                  self._buffer = self._buffer[actualLength:]
              else:
                  data = bytearray()
              return data
          finally:
              self._buffer_lock.release()
docs: ! @brief Extract requested amount of data from the read buffer.