import atexit
from concurrent.futures import _base
+import itertools
import queue
import threading
import weakref
_base.LOGGER.critical('Exception in worker', exc_info=True)
class ThreadPoolExecutor(_base.Executor):
+
+ # Used to assign unique thread names when thread_name_prefix is not supplied.
+ _counter = itertools.count().__next__
+
def __init__(self, max_workers=None, thread_name_prefix=''):
"""Initializes a new ThreadPoolExecutor instance.
self._threads = set()
self._shutdown = False
self._shutdown_lock = threading.Lock()
- self._thread_name_prefix = thread_name_prefix
+ self._thread_name_prefix = (thread_name_prefix or
+ ("ThreadPoolExecutor-%d" % self._counter()))
def submit(self, fn, *args, **kwargs):
with self._shutdown_lock:
del executor
for t in threads:
- # We don't particularly care what the default name is, just that
- # it has a default name implying that it is a ThreadPoolExecutor
- # followed by what looks like a thread number.
- self.assertRegex(t.name, r'^.*ThreadPoolExecutor.*_[0-4]$')
+ # Ensure that our default name is reasonably sane and unique when
+ # no thread_name_prefix was supplied.
+ self.assertRegex(t.name, r'ThreadPoolExecutor-\d+_[0-4]$')
t.join()
--- /dev/null
+Fix concurrent.futures.thread.ThreadPoolExecutor threads to have a non repr()
+based thread name by default when no thread_name_prefix is supplied. They will
+now identify themselves as "ThreadPoolExecutor-y_n".