mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
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.
This commit is contained in:
parent
01c6a8859e
commit
574562c5dd
2 changed files with 6 additions and 3 deletions
|
@ -214,9 +214,8 @@ def as_completed(fs, timeout=None):
|
||||||
if timeout is not None:
|
if timeout is not None:
|
||||||
end_time = timeout + time.time()
|
end_time = timeout + time.time()
|
||||||
|
|
||||||
total_futures = len(fs)
|
|
||||||
|
|
||||||
fs = set(fs)
|
fs = set(fs)
|
||||||
|
total_futures = len(fs)
|
||||||
with _AcquireFutures(fs):
|
with _AcquireFutures(fs):
|
||||||
finished = set(
|
finished = set(
|
||||||
f for f in fs
|
f for f in fs
|
||||||
|
|
|
@ -7,6 +7,7 @@ test.support.import_module('multiprocessing.synchronize')
|
||||||
|
|
||||||
from test.support.script_helper import assert_python_ok
|
from test.support.script_helper import assert_python_ok
|
||||||
|
|
||||||
|
import itertools
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
@ -395,8 +396,11 @@ class AsCompletedTests:
|
||||||
def test_duplicate_futures(self):
|
def test_duplicate_futures(self):
|
||||||
# Issue 20367. Duplicate futures should not raise exceptions or give
|
# Issue 20367. Duplicate futures should not raise exceptions or give
|
||||||
# duplicate responses.
|
# duplicate responses.
|
||||||
|
# Issue #31641: accept arbitrary iterables.
|
||||||
future1 = self.executor.submit(time.sleep, 2)
|
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)
|
self.assertEqual(len(completed), 1)
|
||||||
|
|
||||||
def test_free_reference_yielded_future(self):
|
def test_free_reference_yielded_future(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue