Skip to content

Commit b28a996

Browse files
committed
allow timeout + buffersize
1 parent d8c3949 commit b28a996

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

Doc/library/concurrent.futures.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ Executor Objects
5555
if :meth:`~iterator.__next__` is called and the result isn't available
5656
after *timeout* seconds from the original call to :meth:`Executor.map`.
5757
*timeout* can be an int or a float. If *timeout* is not specified or
58-
``None``, there is no limit to the wait time. Incompatible with
59-
*buffersize*.
58+
``None``, there is no limit to the wait time.
6059

6160
If a *fn* call raises an exception, then that exception will be
6261
raised when its value is retrieved from the iterator.

Lib/concurrent/futures/_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
581581
fn: A callable that will take as many arguments as there are
582582
passed iterables.
583583
timeout: The maximum number of seconds to wait. If None, then there
584-
is no limit on the wait time. Incompatible with buffersize.
584+
is no limit on the wait time.
585585
chunksize: The size of the chunks the iterable will be broken into
586586
before being passed to a child process. This argument is only
587587
used by ProcessPoolExecutor; it is ignored by
@@ -603,9 +603,6 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
603603
if buffersize is not None and buffersize < 1:
604604
raise ValueError("buffersize must be None or >= 1.")
605605

606-
if buffersize is not None and timeout is not None:
607-
raise ValueError("cannot specify both buffersize and timeout.")
608-
609606
if timeout is not None:
610607
end_time = timeout + time.monotonic()
611608

Lib/concurrent/futures/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
812812
fn: A callable that will take as many arguments as there are
813813
passed iterables.
814814
timeout: The maximum number of seconds to wait. If None, then there
815-
is no limit on the wait time. Incompatible with buffersize.
815+
is no limit on the wait time.
816816
chunksize: If greater than one, the iterables will be chopped into
817817
chunks of size chunksize and submitted to the process pool.
818818
If set to one, the items in the list will be sent one at a time.

Lib/test/test_concurrent_futures/executor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ def test_map_timeout(self):
7676
def test_map_with_buffersize(self):
7777
with self.assertRaisesRegex(ValueError, "buffersize must be None or >= 1."):
7878
self.executor.map(bool, [], buffersize=0)
79-
with self.assertRaisesRegex(
80-
ValueError, "cannot specify both buffersize and timeout."
81-
):
82-
self.executor.map(bool, [], timeout=1, buffersize=1)
8379

8480
it = range(4)
8581
self.assertEqual(
8682
list(self.executor.map(str, it, buffersize=1)),
8783
list(map(str, it)),
8884
)
8985

86+
def test_map_with_buffersize_and_timeout(self):
87+
it = self.executor.map(time.sleep, (0, 1), timeout=0.5)
88+
next(it)
89+
with self.assertRaises(TimeoutError):
90+
next(it)
91+
9092
def test_map_with_buffersize_on_infinite_iterable(self):
9193
results = self.executor.map(str, itertools.count(1), buffersize=1)
9294
self.assertEqual(next(iter(results)), "1")

0 commit comments

Comments
 (0)