code: def stop(self):
          
          self._running = False
  
          if self._socket is None:
              return
          try:
              self._socket.shutdown(socket.SHUT_RDWR)
              self._socket.close()
          except socket.error:
              pass
          self._socket = None
docs: Stops read loop and closes socket if it has been created.