def stop(self, wait=True):
        """ Stop the thread.

        More precisely, sends the stopping signal to the thread. It is then up to the run method to correctly responds.

        """
        if self.started:
            self._running.clear()
            self._resume.set()

            # We cannot wait for ourself
            if wait and (threading.current_thread() != self._thread):
                while self._thread.is_alive():
                    self._running.clear()
                    self._resume.set()
                    self._thread.join(timeout=1.0)

            self._started.clear()
            self._resume.clear()