File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
Original file line number Diff line number Diff line change 7
7
8
8
import atexit
9
9
from concurrent .futures import _base
10
+ import itertools
10
11
import queue
11
12
import threading
12
13
import weakref
@@ -81,6 +82,10 @@ def _worker(executor_reference, work_queue):
81
82
_base .LOGGER .critical ('Exception in worker' , exc_info = True )
82
83
83
84
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
+
84
89
def __init__ (self , max_workers = None , thread_name_prefix = '' ):
85
90
"""Initializes a new ThreadPoolExecutor instance.
86
91
@@ -101,7 +106,8 @@ def __init__(self, max_workers=None, thread_name_prefix=''):
101
106
self ._threads = set ()
102
107
self ._shutdown = False
103
108
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 ()))
105
111
106
112
def submit (self , fn , * args , ** kwargs ):
107
113
with self ._shutdown_lock :
Original file line number Diff line number Diff line change @@ -172,10 +172,9 @@ def test_thread_names_default(self):
172
172
del executor
173
173
174
174
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]$' )
179
178
t .join ()
180
179
181
180
Original file line number Diff line number Diff line change @@ -371,6 +371,10 @@ Extension Modules
371
371
Library
372
372
-------
373
373
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
+
374
378
- [Security] bpo-30694: Upgrade expat copy from 2.2.0 to 2.2.1 to get fixes
375
379
of multiple security vulnerabilities including: CVE-2017-9233 (External
376
380
entity infinite loop DoS), CVE-2016-9063 (Integer overflow, re-fix),
You can’t perform that action at this time.
0 commit comments