bpo-31641: Allow arbitrary iterables in `concurrent.futures.as_comple… · python/cpython@574562c (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -214,9 +214,8 @@ def as_completed(fs, timeout=None):
214 214 if timeout is not None:
215 215 end_time = timeout + time.time()
216 216
217 -total_futures = len(fs)
218 -
219 217 fs = set(fs)
218 +total_futures = len(fs)
220 219 with _AcquireFutures(fs):
221 220 finished = set(
222 221 f for f in fs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
7 7
8 8 from test.support.script_helper import assert_python_ok
9 9
10 +import itertools
10 11 import os
11 12 import sys
12 13 import threading
@@ -395,8 +396,11 @@ def test_zero_timeout(self):
395 396 def test_duplicate_futures(self):
396 397 # Issue 20367. Duplicate futures should not raise exceptions or give
397 398 # duplicate responses.
399 +# Issue #31641: accept arbitrary iterables.
398 400 future1 = self.executor.submit(time.sleep, 2)
399 -completed = [f for f in futures.as_completed([future1,future1])]
401 +completed = [
402 +f for f in futures.as_completed(itertools.repeat(future1, 3))
403 + ]
400 404 self.assertEqual(len(completed), 1)
401 405
402 406 def test_free_reference_yielded_future(self):