Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e5c867a

Browse filesBrowse files
committed
allow timeout + buffersize
1 parent fb33d56 commit e5c867a
Copy full SHA for e5c867a

File tree

Expand file treeCollapse file tree

4 files changed

+9
-11
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+9
-11
lines changed

‎Doc/library/concurrent.futures.rst

Copy file name to clipboardExpand all lines: Doc/library/concurrent.futures.rst
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ Executor Objects
5454
if :meth:`~iterator.__next__` is called and the result isn't available
5555
after *timeout* seconds from the original call to :meth:`Executor.map`.
5656
*timeout* can be an int or a float. If *timeout* is not specified or
57-
``None``, there is no limit to the wait time. Incompatible with
58-
*buffersize*.
57+
``None``, there is no limit to the wait time.
5958

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

‎Lib/concurrent/futures/_base.py

Copy file name to clipboardExpand all lines: Lib/concurrent/futures/_base.py
+1-4Lines 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

Copy file name to clipboardExpand all lines: Lib/concurrent/futures/process.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
820820
fn: A callable that will take as many arguments as there are
821821
passed iterables.
822822
timeout: The maximum number of seconds to wait. If None, then there
823-
is no limit on the wait time. Incompatible with buffersize.
823+
is no limit on the wait time.
824824
chunksize: If greater than one, the iterables will be chopped into
825825
chunks of size chunksize and submitted to the process pool.
826826
If set to one, the items in the list will be sent one at a time.

‎Lib/test/test_concurrent_futures/executor.py

Copy file name to clipboardExpand all lines: Lib/test/test_concurrent_futures/executor.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,19 @@ def test_map_timeout(self):
7474
def test_map_with_buffersize(self):
7575
with self.assertRaisesRegex(ValueError, "buffersize must be None or >= 1."):
7676
self.executor.map(bool, [], buffersize=0)
77-
with self.assertRaisesRegex(
78-
ValueError, "cannot specify both buffersize and timeout."
79-
):
80-
self.executor.map(bool, [], timeout=1, buffersize=1)
8177

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

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.