[Python-checkins] [3.6] bpo-31641: Allow arbitrary iterables in `concurrent.futures.as_completed()` (GH-3830) (#3831)

Łukasz Langa webhook-mailer at python.org
Fri Sep 29 18:07:05 EDT 2017


https://github.com/python/cpython/commit/9ef28b6ad3d5aff767e3d852499def8b5ae5ff5d
commit: 9ef28b6ad3d5aff767e3d852499def8b5ae5ff5d
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Łukasz Langa <lukasz at langa.pl>
date: 2017-09-29T15:07:01-07:00
summary:

[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 574562c5ddb2f0429aab9af762442e6f9a3f26ab)

files:
M Lib/concurrent/futures/_base.py
M Lib/test/test_concurrent_futures.py

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 667878429fc..5ddce09a08b 100644
--- a/Lib/test/test_concurrent_futures.py
+++ b/Lib/test/test_concurrent_futures.py
@@ -11,6 +11,7 @@
 
 from test.support.script_helper import assert_python_ok
 
+import itertools
 import os
 import sys
 import threading
@@ -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):



More information about the Python-checkins mailing list