summaryrefslogtreecommitdiff
path: root/Lib/concurrent/futures/thread.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-10-22 03:21:36 +0000
committerMartin Panter <vadmium+py@gmail.com>2016-10-22 03:21:36 +0000
commit73a0af3545f0e9b62ac149367c0cfbdbfe40afe4 (patch)
tree9db0bac0a71ca7296ff714745c0f4eee0b07f6a5 /Lib/concurrent/futures/thread.py
parent6f5021addeb1d9ddd3610409d2461ec79870f9a5 (diff)
parent6fec8a2a83b0f93a80bb83e76dceeda1cf9d00dc (diff)
downloadcpython-73a0af3545f0e9b62ac149367c0cfbdbfe40afe4.tar.gz
Issue #28435: Merge urllib test fixes from 3.5 into 3.6
Diffstat (limited to 'Lib/concurrent/futures/thread.py')
-rw-r--r--Lib/concurrent/futures/thread.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py
index 9c3aec9afa..03d276b63f 100644
--- a/Lib/concurrent/futures/thread.py
+++ b/Lib/concurrent/futures/thread.py
@@ -81,12 +81,13 @@ def _worker(executor_reference, work_queue):
_base.LOGGER.critical('Exception in worker', exc_info=True)
class ThreadPoolExecutor(_base.Executor):
- def __init__(self, max_workers=None):
+ def __init__(self, max_workers=None, thread_name_prefix=''):
"""Initializes a new ThreadPoolExecutor instance.
Args:
max_workers: The maximum number of threads that can be used to
execute the given calls.
+ thread_name_prefix: An optional name prefix to give our threads.
"""
if max_workers is None:
# Use this number because ThreadPoolExecutor is often
@@ -100,6 +101,7 @@ class ThreadPoolExecutor(_base.Executor):
self._threads = set()
self._shutdown = False
self._shutdown_lock = threading.Lock()
+ self._thread_name_prefix = thread_name_prefix
def submit(self, fn, *args, **kwargs):
with self._shutdown_lock:
@@ -121,8 +123,11 @@ class ThreadPoolExecutor(_base.Executor):
q.put(None)
# TODO(bquinlan): Should avoid creating new threads if there are more
# idle threads than items in the work queue.
- if len(self._threads) < self._max_workers:
- t = threading.Thread(target=_worker,
+ num_threads = len(self._threads)
+ if 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,
args=(weakref.ref(self, weakref_cb),
self._work_queue))
t.daemon = True