Skip to content

Commit

Permalink
[3.6] bpo-31641: Allow arbitrary iterables in `concurrent.futures.as_…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
miss-islington authored and ned-deily committed Oct 3, 2017
1 parent a74ce09 commit 2e3fd03
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Lib/concurrent/futures/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,8 @@ def as_completed(fs, timeout=None):
if timeout is not None:
end_time = timeout + time.time()

total_futures = len(fs)

fs = set(fs)
total_futures = len(fs)
with _AcquireFutures(fs):
finished = set(
f for f in fs
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_concurrent_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from test.support.script_helper import assert_python_ok

import itertools
import os
import sys
import threading
Expand Down Expand Up @@ -399,8 +400,11 @@ def test_zero_timeout(self):
def test_duplicate_futures(self):
# Issue 20367. Duplicate futures should not raise exceptions or give
# duplicate responses.
# Issue #31641: accept arbitrary iterables.
future1 = self.executor.submit(time.sleep, 2)
completed = [f for f in futures.as_completed([future1,future1])]
completed = [
f for f in futures.as_completed(itertools.repeat(future1, 3))
]
self.assertEqual(len(completed), 1)

def test_free_reference_yielded_future(self):
Expand Down

0 comments on commit 2e3fd03

Please sign in to comment.