Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a3d91b4

Browse filesBrowse files
authored
bpo-29212: Fix the ugly repr() ThreadPoolExecutor thread name. (#2315)
bpo-29212: Fix the ugly ThreadPoolExecutor thread name. Fixes the newly introduced ugly default thread name for concurrent.futures thread.ThreadPoolExecutor threads. They'll now resemble the old <=3.5 threading default Thread-x names by being named ThreadPoolExecutor-y_n.
1 parent a0e911b commit a3d91b4
Copy full SHA for a3d91b4

File tree

Expand file treeCollapse file tree

3 files changed

+14
-5
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+14
-5
lines changed

‎Lib/concurrent/futures/thread.py

Copy file name to clipboardExpand all lines: Lib/concurrent/futures/thread.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import atexit
99
from concurrent.futures import _base
10+
import itertools
1011
import queue
1112
import threading
1213
import weakref
@@ -81,6 +82,10 @@ def _worker(executor_reference, work_queue):
8182
_base.LOGGER.critical('Exception in worker', exc_info=True)
8283

8384
class ThreadPoolExecutor(_base.Executor):
85+
86+
# Used to assign unique thread names when thread_name_prefix is not supplied.
87+
_counter = itertools.count().__next__
88+
8489
def __init__(self, max_workers=None, thread_name_prefix=''):
8590
"""Initializes a new ThreadPoolExecutor instance.
8691
@@ -101,7 +106,8 @@ def __init__(self, max_workers=None, thread_name_prefix=''):
101106
self._threads = set()
102107
self._shutdown = False
103108
self._shutdown_lock = threading.Lock()
104-
self._thread_name_prefix = thread_name_prefix
109+
self._thread_name_prefix = (thread_name_prefix or
110+
("ThreadPoolExecutor-%d" % self._counter()))
105111

106112
def submit(self, fn, *args, **kwargs):
107113
with self._shutdown_lock:

‎Lib/test/test_concurrent_futures.py

Copy file name to clipboardExpand all lines: Lib/test/test_concurrent_futures.py
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@ def test_thread_names_default(self):
172172
del executor
173173

174174
for t in threads:
175-
# We don't particularly care what the default name is, just that
176-
# it has a default name implying that it is a ThreadPoolExecutor
177-
# followed by what looks like a thread number.
178-
self.assertRegex(t.name, r'^.*ThreadPoolExecutor.*_[0-4]$')
175+
# Ensure that our default name is reasonably sane and unique when
176+
# no thread_name_prefix was supplied.
177+
self.assertRegex(t.name, r'ThreadPoolExecutor-\d+_[0-4]$')
179178
t.join()
180179

181180

‎Misc/NEWS

Copy file name to clipboardExpand all lines: Misc/NEWS
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ Extension Modules
371371
Library
372372
-------
373373

374+
- bpo-29212: Fix concurrent.futures.thread.ThreadPoolExecutor threads to have
375+
a non repr() based thread name by default when no thread_name_prefix is
376+
supplied. They will now identify themselves as "ThreadPoolExecutor-y_n".
377+
374378
- [Security] bpo-30694: Upgrade expat copy from 2.2.0 to 2.2.1 to get fixes
375379
of multiple security vulnerabilities including: CVE-2017-9233 (External
376380
entity infinite loop DoS), CVE-2016-9063 (Integer overflow, re-fix),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.