Skip to content

Commit 4c1f967

Browse files
[3.14] gh-150285: Fix too long docstrings in the concurrent package (GH-151076) (GH-151174)
(cherry picked from commit 0fa06f4) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 9d92876 commit 4c1f967

4 files changed

Lines changed: 89 additions & 79 deletions

File tree

Lib/concurrent/futures/_base.py

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ def as_completed(fs, timeout=None):
194194
"""An iterator over the given futures that yields each as it completes.
195195
196196
Args:
197-
fs: The sequence of Futures (possibly created by different Executors) to
198-
iterate over.
199-
timeout: The maximum number of seconds to wait. If None, then there
200-
is no limit on the wait time.
197+
fs: The sequence of Futures (possibly created by different
198+
Executors) to iterate over.
199+
timeout: The maximum number of seconds to wait. If None, then
200+
there is no limit on the wait time.
201201
202202
Returns:
203-
An iterator that yields the given Futures as they complete (finished or
204-
cancelled). If any given Futures are duplicated, they will be returned
205-
once.
203+
An iterator that yields the given Futures as they complete
204+
(finished or cancelled). If any given Futures are duplicated,
205+
they will be returned once.
206206
207207
Raises:
208208
TimeoutError: If the entire result iterator could not be generated
@@ -258,19 +258,20 @@ def wait(fs, timeout=None, return_when=ALL_COMPLETED):
258258
"""Wait for the futures in the given sequence to complete.
259259
260260
Args:
261-
fs: The sequence of Futures (possibly created by different Executors) to
262-
wait upon.
263-
timeout: The maximum number of seconds to wait. If None, then there
264-
is no limit on the wait time.
265-
return_when: Indicates when this function should return. The options
266-
are:
261+
fs: The sequence of Futures (possibly created by different
262+
Executors) to wait upon.
263+
timeout: The maximum number of seconds to wait. If None, then
264+
there is no limit on the wait time.
265+
return_when: Indicates when this function should return.
266+
The options are:
267267
268268
FIRST_COMPLETED - Return when any future finishes or is
269269
cancelled.
270270
FIRST_EXCEPTION - Return when any future finishes by raising an
271-
exception. If no future raises an exception
271+
exception. If no future raises an exception
272272
then it is equivalent to ALL_COMPLETED.
273-
ALL_COMPLETED - Return when all futures finish or are cancelled.
273+
ALL_COMPLETED - Return when all futures finish or are
274+
cancelled.
274275
275276
Returns:
276277
A named 2-tuple of sets. The first set, named 'done', contains the
@@ -404,11 +405,12 @@ def add_done_callback(self, fn):
404405
405406
Args:
406407
fn: A callable that will be called with this future as its only
407-
argument when the future completes or is cancelled. The callable
408-
will always be called by a thread in the same process in which
409-
it was added. If the future has already completed or been
410-
cancelled then the callable will be called immediately. These
411-
callables are called in the order that they were added.
408+
argument when the future completes or is cancelled. The
409+
callable will always be called by a thread in the same
410+
process in which it was added. If the future has already
411+
completed or been cancelled then the callable will be
412+
called immediately. These callables are called in the
413+
order that they were added.
412414
"""
413415
with self._condition:
414416
if self._state not in [CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED]:
@@ -423,17 +425,19 @@ def result(self, timeout=None):
423425
"""Return the result of the call that the future represents.
424426
425427
Args:
426-
timeout: The number of seconds to wait for the result if the future
427-
isn't done. If None, then there is no limit on the wait time.
428+
timeout: The number of seconds to wait for the result if the
429+
future isn't done. If None, then there is no limit on the
430+
wait time.
428431
429432
Returns:
430433
The result of the call that the future represents.
431434
432435
Raises:
433436
CancelledError: If the future was cancelled.
434-
TimeoutError: If the future didn't finish executing before the given
435-
timeout.
436-
Exception: If the call raised then that exception will be raised.
437+
TimeoutError: If the future didn't finish executing before the
438+
given timeout.
439+
Exception: If the call raised then that exception will be
440+
raised.
437441
"""
438442
try:
439443
with self._condition:
@@ -459,17 +463,17 @@ def exception(self, timeout=None):
459463
460464
Args:
461465
timeout: The number of seconds to wait for the exception if the
462-
future isn't done. If None, then there is no limit on the wait
463-
time.
466+
future isn't done. If None, then there is no limit on the
467+
wait time.
464468
465469
Returns:
466-
The exception raised by the call that the future represents or None
467-
if the call completed without raising.
470+
The exception raised by the call that the future represents or
471+
None if the call completed without raising.
468472
469473
Raises:
470474
CancelledError: If the future was cancelled.
471-
TimeoutError: If the future didn't finish executing before the given
472-
timeout.
475+
TimeoutError: If the future didn't finish executing before the
476+
given timeout.
473477
"""
474478

475479
with self._condition:
@@ -494,22 +498,23 @@ def set_running_or_notify_cancel(self):
494498
Should only be used by Executor implementations and unit tests.
495499
496500
If the future has been cancelled (cancel() was called and returned
497-
True) then any threads waiting on the future completing (though calls
498-
to as_completed() or wait()) are notified and False is returned.
501+
True) then any threads waiting on the future completing (though
502+
calls to as_completed() or wait()) are notified and False is
503+
returned.
499504
500505
If the future was not cancelled then it is put in the running state
501506
(future calls to running() will return True) and True is returned.
502507
503508
This method should be called by Executor implementations before
504-
executing the work associated with this future. If this method returns
505-
False then the work should not be executed.
509+
executing the work associated with this future. If this method
510+
returns False then the work should not be executed.
506511
507512
Returns:
508513
False if the Future was cancelled, True otherwise.
509514
510515
Raises:
511-
RuntimeError: if this method was already called or if set_result()
512-
or set_exception() was called.
516+
RuntimeError: if this method was already called or if
517+
set_result() or set_exception() was called.
513518
"""
514519
with self._condition:
515520
if self._state == CANCELLED:
@@ -566,8 +571,9 @@ class Executor(object):
566571
def submit(self, fn, /, *args, **kwargs):
567572
"""Submits a callable to be executed with the given arguments.
568573
569-
Schedules the callable to be executed as fn(*args, **kwargs) and returns
570-
a Future instance representing the execution of the callable.
574+
Schedules the callable to be executed as fn(*args, **kwargs) and
575+
returns a Future instance representing the execution of the
576+
callable.
571577
572578
Returns:
573579
A Future representing the given call.
@@ -580,25 +586,25 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
580586
Args:
581587
fn: A callable that will take as many arguments as there are
582588
passed iterables.
583-
timeout: The maximum number of seconds to wait. If None, then there
584-
is no limit on the wait time.
585-
chunksize: The size of the chunks the iterable will be broken into
586-
before being passed to a child process. This argument is only
587-
used by ProcessPoolExecutor; it is ignored by
589+
timeout: The maximum number of seconds to wait. If None, then
590+
there is no limit on the wait time.
591+
chunksize: The size of the chunks the iterable will be broken
592+
into before being passed to a child process. This argument
593+
is only used by ProcessPoolExecutor; it is ignored by
588594
ThreadPoolExecutor.
589595
buffersize: The number of submitted tasks whose results have not
590-
yet been yielded. If the buffer is full, iteration over the
596+
yet been yielded. If the buffer is full, iteration over the
591597
iterables pauses until a result is yielded from the buffer.
592-
If None, all input elements are eagerly collected, and a task is
593-
submitted for each.
598+
If None, all input elements are eagerly collected, and
599+
a task is submitted for each.
594600
595601
Returns:
596-
An iterator equivalent to: map(func, *iterables) but the calls may
597-
be evaluated out-of-order.
602+
An iterator equivalent to: map(func, *iterables) but the calls
603+
may be evaluated out-of-order.
598604
599605
Raises:
600-
TimeoutError: If the entire result iterator could not be generated
601-
before the given timeout.
606+
TimeoutError: If the entire result iterator could not be
607+
generated before the given timeout.
602608
Exception: If fn(*args) raises for any values.
603609
"""
604610
if buffersize is not None and not isinstance(buffersize, int):
@@ -652,8 +658,8 @@ def shutdown(self, wait=True, *, cancel_futures=False):
652658
653659
Args:
654660
wait: If True then shutdown will not return until all running
655-
futures have finished executing and the resources used by the
656-
executor have been reclaimed.
661+
futures have finished executing and the resources used by
662+
the executor have been reclaimed.
657663
cancel_futures: If True then shutdown will cancel all pending
658664
futures. Futures that are completed or running will not be
659665
cancelled.

Lib/concurrent/futures/interpreter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def __init__(self, max_workers=None, thread_name_prefix='',
110110
"""Initializes a new InterpreterPoolExecutor instance.
111111
112112
Args:
113-
max_workers: The maximum number of interpreters that can be used to
114-
execute the given calls.
113+
max_workers: The maximum number of interpreters that can be used
114+
to execute the given calls.
115115
thread_name_prefix: An optional name prefix to give our threads.
116116
initializer: A callable or script used to initialize
117117
each worker interpreter.

Lib/concurrent/futures/process.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -642,19 +642,21 @@ def __init__(self, max_workers=None, mp_context=None,
642642
643643
Args:
644644
max_workers: The maximum number of processes that can be used to
645-
execute the given calls. If None or not given then as many
646-
worker processes will be created as the machine has processors.
647-
mp_context: A multiprocessing context to launch the workers created
648-
using the multiprocessing.get_context('start method') API. This
649-
object should provide SimpleQueue, Queue and Process.
645+
execute the given calls. If None or not given then as many
646+
worker processes will be created as the machine has
647+
processors.
648+
mp_context: A multiprocessing context to launch the workers
649+
created using the multiprocessing.get_context('start method')
650+
API. This object should provide SimpleQueue, Queue and
651+
Process.
650652
initializer: A callable used to initialize worker processes.
651653
initargs: A tuple of arguments to pass to the initializer.
652-
max_tasks_per_child: The maximum number of tasks a worker process
653-
can complete before it will exit and be replaced with a fresh
654-
worker process. The default of None means worker process will
655-
live as long as the executor. Requires a non-'fork' mp_context
656-
start method. When given, we default to using 'spawn' if no
657-
mp_context is supplied.
654+
max_tasks_per_child: The maximum number of tasks a worker
655+
process can complete before it will exit and be replaced
656+
with a fresh worker process. The default of None means
657+
worker process will live as long as the executor. Requires
658+
a non-'fork' mp_context start method. When given, we
659+
default to using 'spawn' if no mp_context is supplied.
658660
"""
659661
_check_system_limits()
660662

@@ -824,24 +826,25 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
824826
Args:
825827
fn: A callable that will take as many arguments as there are
826828
passed iterables.
827-
timeout: The maximum number of seconds to wait. If None, then there
828-
is no limit on the wait time.
829-
chunksize: If greater than one, the iterables will be chopped into
830-
chunks of size chunksize and submitted to the process pool.
831-
If set to one, the items in the list will be sent one at a time.
829+
timeout: The maximum number of seconds to wait. If None, then
830+
there is no limit on the wait time.
831+
chunksize: If greater than one, the iterables will be chopped
832+
into chunks of size chunksize and submitted to the process
833+
pool. If set to one, the items in the list will be sent
834+
one at a time.
832835
buffersize: The number of submitted tasks whose results have not
833-
yet been yielded. If the buffer is full, iteration over the
836+
yet been yielded. If the buffer is full, iteration over the
834837
iterables pauses until a result is yielded from the buffer.
835-
If None, all input elements are eagerly collected, and a task is
836-
submitted for each.
838+
If None, all input elements are eagerly collected, and
839+
a task is submitted for each.
837840
838841
Returns:
839-
An iterator equivalent to: map(func, *iterables) but the calls may
840-
be evaluated out-of-order.
842+
An iterator equivalent to: map(func, *iterables) but the calls
843+
may be evaluated out-of-order.
841844
842845
Raises:
843-
TimeoutError: If the entire result iterator could not be generated
844-
before the given timeout.
846+
TimeoutError: If the entire result iterator could not be
847+
generated before the given timeout.
845848
Exception: If fn(*args) raises for any values.
846849
"""
847850
if chunksize < 1:

Lib/concurrent/interpreters/_queues.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def put(self, obj, block=True, timeout=None, *,
186186
underlying data is actually shared. Furthermore, some types
187187
can be sent through a queue more efficiently than others. This
188188
group includes various immutable types like int, str, bytes, and
189-
tuple (if the items are likewise efficiently shareable). See interpreters.is_shareable().
189+
tuple (if the items are likewise efficiently shareable).
190+
See interpreters.is_shareable().
190191
191192
"unbounditems" controls the behavior of Queue.get() for the given
192193
object if the current interpreter (calling put()) is later

0 commit comments

Comments
 (0)