'Stops running threads and wait for them to exit, if necessary.
Should be called by the same thread which called `start()`.
# Arguments
timeout: maximum time to wait on `thread.join()`.'

def stop(self, timeout=None):

    if self.is_running():
        self._stop_event.set()
    for thread in self._threads:
        if thread.is_alive():
            if self._use_multiprocessing:
                thread.terminate()
            else:
                thread.join(timeout)
    if self._use_multiprocessing:
        if (self.queue is not None):
            self.queue.close()
    self._threads = []
    self._stop_event = None
    self.queue = None
