Skip to content

Commit 574562c

Browse files
authored
bpo-31641: Allow arbitrary iterables in concurrent.futures.as_completed() (#3830)
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.
1 parent 01c6a88 commit 574562c

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
@@ -7,6 +7,7 @@
77

88
from test.support.script_helper import assert_python_ok
99

10+
import itertools
1011
import os
1112
import sys
1213
import threading
@@ -395,8 +396,11 @@ def test_zero_timeout(self):
395396
def test_duplicate_futures(self):
396397
# Issue 20367. Duplicate futures should not raise exceptions or give
397398
# duplicate responses.
399+
# Issue #31641: accept arbitrary iterables.
398400
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+
]
400404
self.assertEqual(len(completed), 1)
401405

402406
def test_free_reference_yielded_future(self):

0 commit comments

Comments
 (0)