diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-27 08:11:48 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-27 08:11:48 (GMT) |
commit | b9915973f3522d3feaa862aaacd4d7d269f6fc72 (patch) | |
tree | e30a6634ad08bd39d80f606075d763b029b6b40b /Lib | |
parent | d1c85fd2835bafa0fde0b95b82b6e0fffd60649a (diff) | |
download | cpython-b9915973f3522d3feaa862aaacd4d7d269f6fc72.zip cpython-b9915973f3522d3feaa862aaacd4d7d269f6fc72.tar.gz cpython-b9915973f3522d3feaa862aaacd4d7d269f6fc72.tar.bz2 |
Issue #20367: Fix behavior of concurrent.futures.as_completed() for duplicate
arguments. Patch by Glenn Langford.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/concurrent/futures/_base.py | 6 | ||||
-rw-r--r-- | Lib/test/test_concurrent_futures.py | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py index ca3aebd..d45a404 100644 --- a/Lib/concurrent/futures/_base.py +++ b/Lib/concurrent/futures/_base.py @@ -181,7 +181,8 @@ def as_completed(fs, timeout=None): Returns: An iterator that yields the given Futures as they complete (finished or - cancelled). + cancelled). If any given Futures are duplicated, they will be returned + once. Raises: TimeoutError: If the entire result iterator could not be generated @@ -190,11 +191,12 @@ def as_completed(fs, timeout=None): if timeout is not None: end_time = timeout + time.time() + fs = set(fs) with _AcquireFutures(fs): finished = set( f for f in fs if f._state in [CANCELLED_AND_NOTIFIED, FINISHED]) - pending = set(fs) - finished + pending = fs - finished waiter = _create_and_install_waiters(fs, _AS_COMPLETED) try: diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 39230e1..04c4c37 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -344,6 +344,13 @@ class AsCompletedTests: SUCCESSFUL_FUTURE]), completed_futures) + def test_duplicate_futures(self): + # Issue 20367. Duplicate futures should not raise exceptions or give + # duplicate responses. + future1 = self.executor.submit(time.sleep, 2) + completed = [f for f in futures.as_completed([future1,future1])] + self.assertEqual(len(completed), 1) + class ThreadPoolAsCompletedTests(ThreadPoolMixin, AsCompletedTests, unittest.TestCase): pass |