Skip to content

Commit 68ac574

Browse files
[3.15] gh-124694: Document missing ctxkwargs argument in ThreadPoolExecutor (GH-134321) (GH-160459)
(cherry picked from commit 9a4187a) Co-authored-by: Semyon Moroz <donbarbos@proton.me>
1 parent 47163e5 commit 68ac574

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

‎Doc/library/concurrent.futures.rst‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Executor Objects
119119
e.submit(shutil.copy, 'src4.txt', 'dest4.txt')
120120

121121
.. versionchanged:: 3.9
122-
Added *cancel_futures*.
122+
Added the *cancel_futures* parameter.
123123

124124

125125
ThreadPoolExecutor
@@ -161,7 +161,8 @@ And::
161161
# the single worker thread is already waiting for wait_on_future().
162162

163163

164-
.. class:: ThreadPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())
164+
.. class:: ThreadPoolExecutor(max_workers=None, thread_name_prefix='', \
165+
initializer=None, initargs=(), **ctxkwargs)
165166
166167
An :class:`Executor` subclass that uses a pool of at most *max_workers*
167168
threads to execute calls asynchronously.
@@ -179,6 +180,18 @@ And::
179180
pending jobs will raise a :exc:`~concurrent.futures.thread.BrokenThreadPool`,
180181
as well as any attempt to submit more jobs to the pool.
181182

183+
*ctxkwargs* is a mapping of additional keyword arguments passed to
184+
:meth:`prepare_context`, allowing customization of the worker execution
185+
context.
186+
187+
.. classmethod:: prepare_context(initializer, initargs)
188+
189+
Setting up the necessary context for creating worker instances in a
190+
pool-based executor (for example, in a concurrent environment like
191+
threads or interpreters).
192+
193+
.. versionadded:: 3.14
194+
182195
.. versionchanged:: 3.5
183196
If *max_workers* is ``None`` or
184197
not given, it will default to the number of processors on the machine,
@@ -208,6 +221,10 @@ And::
208221
Default value of *max_workers* is changed to
209222
``min(32, (os.process_cpu_count() or 1) + 4)``.
210223

224+
.. versionchanged:: 3.14
225+
Added *ctxkwargs* to pass additional arguments to :meth:`prepare_context`
226+
class method.
227+
211228

212229
.. _threadpoolexecutor-example:
213230

@@ -296,7 +313,8 @@ efficient alternative is to serialize with :mod:`pickle` and then send
296313
the bytes over a shared :mod:`socket <socket>` or
297314
:func:`pipe <os.pipe>`.
298315

299-
.. class:: InterpreterPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())
316+
.. class:: InterpreterPoolExecutor(max_workers=None, thread_name_prefix='', \
317+
initializer=None, initargs=())
300318

301319
A :class:`ThreadPoolExecutor` subclass that executes calls asynchronously
302320
using a pool of at most *max_workers* threads. Each thread runs
@@ -356,7 +374,9 @@ per :class:`multiprocessing.Process` apply when using :meth:`~Executor.submit`
356374
and :meth:`~Executor.map` on a :class:`ProcessPoolExecutor`. A function defined
357375
in a REPL or a lambda should not be expected to work.
358376

359-
.. class:: ProcessPoolExecutor(max_workers=None, mp_context=None, initializer=None, initargs=(), max_tasks_per_child=None)
377+
.. class:: ProcessPoolExecutor(max_workers=None, mp_context=None, \
378+
initializer=None, initargs=(), \
379+
max_tasks_per_child=None)
360380

361381
An :class:`Executor` subclass that executes calls asynchronously using a pool
362382
of at most *max_workers* processes. If *max_workers* is ``None`` or not

0 commit comments

Comments
 (0)