Stops read loop and closes socket if it has been created.

def stop(self):
        """Stops read loop and closes socket if it has been created.
        """
        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