'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):

    self.stop_signal.set()
    with self.queue.mutex:
        self.queue.queue.clear()
        self.queue.unfinished_tasks = 0
        self.queue.not_full.notify()
    self.executor.close()
    self.executor.join()
    self.run_thread.join(timeout)
