diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py index 70c7b619593..6bace6c7464 100644 --- a/Lib/concurrent/futures/_base.py +++ b/Lib/concurrent/futures/_base.py @@ -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 diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 57dc994d284..e4c9ace9356 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -7,6 +7,7 @@ test.support.import_module('multiprocessing.synchronize') from test.support.script_helper import assert_python_ok +import itertools import os import sys import threading @@ -395,8 +396,11 @@ class AsCompletedTests: 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):