'Stop the worker threads and empty all queues.'

def stop(self):

    with self._state_change:
        if (not self._running):
            return
        self._running = False
        for queue in (self.completion_queue, self.callback_queue):
            queue.put(_STOP)
        self._workers.reverse()
        while self._workers:
            worker = self._workers.pop()
            worker.join()
        self.callback_queue = self.queue_impl()
        self.completion_queue = self.queue_impl()
        if hasattr(atexit, 'unregister'):
            atexit.unregister(self.stop)
