Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
50abe877
Kaydet (Commit)
50abe877
authored
Agu 07, 2016
tarafından
Gregory P. Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #27664: Add to concurrent.futures.thread.ThreadPoolExecutor()
the ability to specify a thread name prefix.
üst
d0d24fd1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
4 deletions
+40
-4
concurrent.futures.rst
Doc/library/concurrent.futures.rst
+5
-1
thread.py
Lib/concurrent/futures/thread.py
+8
-3
test_concurrent_futures.py
Lib/test/test_concurrent_futures.py
+24
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/concurrent.futures.rst
Dosyayı görüntüle @
50abe877
...
...
@@ -124,7 +124,7 @@ And::
executor.submit(wait_on_future)
.. class:: ThreadPoolExecutor(max_workers=None)
.. class:: ThreadPoolExecutor(max_workers=None
, thread_name_prefix=''
)
An :class:`Executor` subclass that uses a pool of at most *max_workers*
threads to execute calls asynchronously.
...
...
@@ -137,6 +137,10 @@ And::
should be higher than the number of workers
for :class:`ProcessPoolExecutor`.
.. versionadded:: 3.6
The *thread_name_prefix* argument was added to allow users to
control the threading.Thread names for worker threads created by
the pool for easier debugging.
.. _threadpoolexecutor-example:
...
...
Lib/concurrent/futures/thread.py
Dosyayı görüntüle @
50abe877
...
...
@@ -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
...
...
Lib/test/test_concurrent_futures.py
Dosyayı görüntüle @
50abe877
...
...
@@ -154,6 +154,30 @@ class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest, unittest.Tes
for
t
in
threads
:
t
.
join
()
def
test_thread_names_assigned
(
self
):
executor
=
futures
.
ThreadPoolExecutor
(
max_workers
=
5
,
thread_name_prefix
=
'SpecialPool'
)
executor
.
map
(
abs
,
range
(
-
5
,
5
))
threads
=
executor
.
_threads
del
executor
for
t
in
threads
:
self
.
assertRegex
(
t
.
name
,
r'^SpecialPool_[0-4]$'
)
t
.
join
()
def
test_thread_names_default
(
self
):
executor
=
futures
.
ThreadPoolExecutor
(
max_workers
=
5
)
executor
.
map
(
abs
,
range
(
-
5
,
5
))
threads
=
executor
.
_threads
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]$'
)
t
.
join
()
class
ProcessPoolShutdownTest
(
ProcessPoolMixin
,
ExecutorShutdownTest
,
unittest
.
TestCase
):
def
_prime_executor
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
50abe877
...
...
@@ -43,6 +43,9 @@ Core and Builtins
Library
-------
-
Issue
#
27664
:
Add
to
concurrent
.
futures
.
thread
.
ThreadPoolExecutor
()
the
ability
to
specify
a
thread
name
prefix
.
-
Issue
#
26750
:
unittest
.
mock
.
create_autospec
()
now
works
properly
for
subclasses
of
property
()
and
other
data
descriptors
.
Removes
the
never
publicly
used
,
never
documented
unittest
.
mock
.
DescriptorTypes
tuple
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment