summaryrefslogtreecommitdiffstats
path: root/Lib/concurrent
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-01-04 13:36:13 (GMT)
committerGitHub <noreply@github.com>2022-01-04 13:36:13 (GMT)
commit7d7817cf0f826e566d8370a0e974bbfed6611d91 (patch)
tree9d7e29dfd0e13cbdc6e0bed9bdca8f457ad12c4f /Lib/concurrent
parentb949845b36b999185ed2bdf8a04dca1da39f3002 (diff)
downloadcpython-7d7817cf0f826e566d8370a0e974bbfed6611d91.zip
cpython-7d7817cf0f826e566d8370a0e974bbfed6611d91.tar.gz
cpython-7d7817cf0f826e566d8370a0e974bbfed6611d91.tar.bz2
bpo-20369: concurrent.futures.wait() now deduplicates futures given a… (GH-30168)
* bpo-20369: concurrent.futures.wait() now deduplicates futures given as arg. * 📜🤖 Added by blurb_it. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/concurrent')
-rw-r--r--Lib/concurrent/futures/_base.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py
index b033739..c5912c2 100644
--- a/Lib/concurrent/futures/_base.py
+++ b/Lib/concurrent/futures/_base.py
@@ -282,13 +282,14 @@ def wait(fs, timeout=None, return_when=ALL_COMPLETED):
A named 2-tuple of sets. The first set, named 'done', contains the
futures that completed (is finished or cancelled) before the wait
completed. The second set, named 'not_done', contains uncompleted
- futures.
+ futures. Duplicate futures given to *fs* are removed and will be
+ returned only once.
"""
+ fs = set(fs)
with _AcquireFutures(fs):
- done = set(f for f in fs
- if f._state in [CANCELLED_AND_NOTIFIED, FINISHED])
- not_done = set(fs) - done
-
+ done = {f for f in fs
+ if f._state in [CANCELLED_AND_NOTIFIED, FINISHED]}
+ not_done = fs - done
if (return_when == FIRST_COMPLETED) and done:
return DoneAndNotDoneFutures(done, not_done)
elif (return_when == FIRST_EXCEPTION) and done:
@@ -307,7 +308,7 @@ def wait(fs, timeout=None, return_when=ALL_COMPLETED):
f._waiters.remove(waiter)
done.update(waiter.finished_futures)
- return DoneAndNotDoneFutures(done, set(fs) - done)
+ return DoneAndNotDoneFutures(done, fs - done)
class Future(object):
"""Represents the result of an asynchronous computation."""