Skip to content

Commit 4d94634

Browse files
gh-150285: Fix too long docstrings in the concurrent package
1 parent 16ede81 commit 4d94634

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:
@@ -593,8 +598,9 @@ class Executor(object):
593598
def submit(self, fn, /, *args, **kwargs):
594599
"""Submits a callable to be executed with the given arguments.
595600
596-
Schedules the callable to be executed as fn(*args, **kwargs) and returns
597-
a Future instance representing the execution of the callable.
601+
Schedules the callable to be executed as fn(*args, **kwargs) and
602+
returns a Future instance representing the execution of the
603+
callable.
598604
599605
Returns:
600606
A Future representing the given call.
@@ -607,25 +613,25 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
607613
Args:
608614
fn: A callable that will take as many arguments as there are
609615
passed iterables.
610-
timeout: The maximum number of seconds to wait. If None, then there
611-
is no limit on the wait time.
612-
chunksize: The size of the chunks the iterable will be broken into
613-
before being passed to a child process. This argument is only
614-
used by ProcessPoolExecutor; it is ignored by
616+
timeout: The maximum number of seconds to wait. If None, then
617+
there is no limit on the wait time.
618+
chunksize: The size of the chunks the iterable will be broken
619+
into before being passed to a child process. This argument
620+
is only used by ProcessPoolExecutor; it is ignored by
615621
ThreadPoolExecutor.
616622
buffersize: The number of submitted tasks whose results have not
617-
yet been yielded. If the buffer is full, iteration over the
623+
yet been yielded. If the buffer is full, iteration over the
618624
iterables pauses until a result is yielded from the buffer.
619-
If None, all input elements are eagerly collected, and a task is
620-
submitted for each.
625+
If None, all input elements are eagerly collected, and
626+
a task is submitted for each.
621627
622628
Returns:
623-
An iterator equivalent to: map(func, *iterables) but the calls may
624-
be evaluated out-of-order.
629+
An iterator equivalent to: map(func, *iterables) but the calls
630+
may be evaluated out-of-order.
625631
626632
Raises:
627-
TimeoutError: If the entire result iterator could not be generated
628-
before the given timeout.
633+
TimeoutError: If the entire result iterator could not be
634+
generated before the given timeout.
629635
Exception: If fn(*args) raises for any values.
630636
"""
631637
if buffersize is not None and not isinstance(buffersize, int):
@@ -679,8 +685,8 @@ def shutdown(self, wait=True, *, cancel_futures=False):
679685
680686
Args:
681687
wait: If True then shutdown will not return until all running
682-
futures have finished executing and the resources used by the
683-
executor have been reclaimed.
688+
futures have finished executing and the resources used by
689+
the executor have been reclaimed.
684690
cancel_futures: If True then shutdown will cancel all pending
685691
futures. Futures that are completed or running will not be
686692
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
@@ -656,19 +656,21 @@ def __init__(self, max_workers=None, mp_context=None,
656656
657657
Args:
658658
max_workers: The maximum number of processes that can be used to
659-
execute the given calls. If None or not given then as many
660-
worker processes will be created as the machine has processors.
661-
mp_context: A multiprocessing context to launch the workers created
662-
using the multiprocessing.get_context('start method') API. This
663-
object should provide SimpleQueue, Queue and Process.
659+
execute the given calls. If None or not given then as many
660+
worker processes will be created as the machine has
661+
processors.
662+
mp_context: A multiprocessing context to launch the workers
663+
created using the multiprocessing.get_context('start method')
664+
API. This object should provide SimpleQueue, Queue and
665+
Process.
664666
initializer: A callable used to initialize worker processes.
665667
initargs: A tuple of arguments to pass to the initializer.
666-
max_tasks_per_child: The maximum number of tasks a worker process
667-
can complete before it will exit and be replaced with a fresh
668-
worker process. The default of None means worker process will
669-
live as long as the executor. Requires a non-'fork' mp_context
670-
start method. When given, we default to using 'spawn' if no
671-
mp_context is supplied.
668+
max_tasks_per_child: The maximum number of tasks a worker
669+
process can complete before it will exit and be replaced
670+
with a fresh worker process. The default of None means
671+
worker process will live as long as the executor. Requires
672+
a non-'fork' mp_context start method. When given, we
673+
default to using 'spawn' if no mp_context is supplied.
672674
"""
673675
_check_system_limits()
674676

@@ -838,24 +840,25 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
838840
Args:
839841
fn: A callable that will take as many arguments as there are
840842
passed iterables.
841-
timeout: The maximum number of seconds to wait. If None, then there
842-
is no limit on the wait time.
843-
chunksize: If greater than one, the iterables will be chopped into
844-
chunks of size chunksize and submitted to the process pool.
845-
If set to one, the items in the list will be sent one at a time.
843+
timeout: The maximum number of seconds to wait. If None, then
844+
there is no limit on the wait time.
845+
chunksize: If greater than one, the iterables will be chopped
846+
into chunks of size chunksize and submitted to the process
847+
pool. If set to one, the items in the list will be sent
848+
one at a time.
846849
buffersize: The number of submitted tasks whose results have not
847-
yet been yielded. If the buffer is full, iteration over the
850+
yet been yielded. If the buffer is full, iteration over the
848851
iterables pauses until a result is yielded from the buffer.
849-
If None, all input elements are eagerly collected, and a task is
850-
submitted for each.
852+
If None, all input elements are eagerly collected, and
853+
a task is submitted for each.
851854
852855
Returns:
853-
An iterator equivalent to: map(func, *iterables) but the calls may
854-
be evaluated out-of-order.
856+
An iterator equivalent to: map(func, *iterables) but the calls
857+
may be evaluated out-of-order.
855858
856859
Raises:
857-
TimeoutError: If the entire result iterator could not be generated
858-
before the given timeout.
860+
TimeoutError: If the entire result iterator could not be
861+
generated before the given timeout.
859862
Exception: If fn(*args) raises for any values.
860863
"""
861864
if chunksize < 1:

Lib/concurrent/interpreters/_queues.py

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

0 commit comments

Comments
 (0)