Skip to content

Commit 9ef28b6

Browse files
miss-islingtonambv
authored andcommitted
[3.6] bpo-31641: Allow arbitrary iterables in concurrent.futures.as_completed() (GH-3830) (#3831)
This was possible before. GH-1560 introduced a regression after 3.6.2 got released where only sequences were accepted now. This commit addresses this problem. (cherry picked from commit 574562c)
1 parent 66c2b9f commit 9ef28b6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Lib/concurrent/futures/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,8 @@ def as_completed(fs, timeout=None):
214214
if timeout is not None:
215215
end_time = timeout + time.time()
216216

217-
total_futures = len(fs)
218-
219217
fs = set(fs)
218+
total_futures = len(fs)
220219
with _AcquireFutures(fs):
221220
finished = set(
222221
f for f in fs

Lib/test/test_concurrent_futures.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from test.support.script_helper import assert_python_ok
1313

14+
import itertools
1415
import os
1516
import sys
1617
import threading
@@ -399,8 +400,11 @@ def test_zero_timeout(self):
399400
def test_duplicate_futures(self):
400401
# Issue 20367. Duplicate futures should not raise exceptions or give
401402
# duplicate responses.
403+
# Issue #31641: accept arbitrary iterables.
402404
future1 = self.executor.submit(time.sleep, 2)
403-
completed = [f for f in futures.as_completed([future1,future1])]
405+
completed = [
406+
f for f in futures.as_completed(itertools.repeat(future1, 3))
407+
]
404408
self.assertEqual(len(completed), 1)
405409

406410
def test_free_reference_yielded_future(self):

0 commit comments

Comments
 (0)