--- a/thread.py 2016-11-01 02:09:20.000000000 +0100 +++ b/thread.py 2016-11-09 17:02:58.363326699 +0100 @@ -66,7 +66,12 @@ work_item.run() # Delete references to object. See issue16284 del work_item + work_queue.task_done() continue + + # We can safely call task_done here, if we should shutdown, we will + # just put another None object back into the queue and exit. + work_queue.task_done() executor = executor_reference() # Exit if: # - The interpreter is shutting down OR @@ -124,7 +129,8 @@ # TODO(bquinlan): Should avoid creating new threads if there are more # idle threads than items in the work queue. num_threads = len(self._threads) - if num_threads < self._max_workers: + if self._work_queue.unfinished_tasks > num_threads \ + and num_threads < self._max_workers: thread_name = '%s_%d' % (self._thread_name_prefix or self, num_threads) t = threading.Thread(name=thread_name, target=_worker,