Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(32917)

Unified Diff: Lib/concurrent/futures/thread.py

Issue 27664: Allow specifying prefix for thread name in concurrent.futures.ThreadPoolExecutor
Patch Set: Created 3 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/test/test_concurrent_futures.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/concurrent/futures/thread.py
+++ b/Lib/concurrent/futures/thread.py
@@ -81,7 +81,7 @@ def _worker(executor_reference, work_que
_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=None):
"""Initializes a new ThreadPoolExecutor instance.
Args:
@@ -100,6 +100,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:
@@ -122,7 +123,11 @@ class ThreadPoolExecutor(_base.Executor)
# 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,
+ if self._thread_name_prefix:
+ name = self._thread_name_prefix + '_%d' % len(self._threads)
+ else:
+ name = None
+ t = threading.Thread(name=name, target=_worker,
args=(weakref.ref(self, weakref_cb),
self._work_queue))
t.daemon = True
« no previous file with comments | « no previous file | Lib/test/test_concurrent_futures.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+