◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
3 changes: 2 additions & 1 deletion Doc/library/concurrent.futures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ Module Functions
.. function:: wait(fs, timeout=None, return_when=ALL_COMPLETED)

Wait for the :class:`Future` instances (possibly created by different
:class:`Executor` instances) given by *fs* to complete. Returns a named
2-tuple of sets. The first set, named ``done``, contains the futures that
completed (finished or cancelled futures) before the wait completed. The
second set, named ``not_done``, contains the futures that did not complete
Expand Down
13 changes: 7 additions & 6 deletions Lib/concurrent/futures/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
with _AcquireFutures(fs):
done = set(f for f in fs
if f._state in [CANCELLED_AND_NOTIFIED, FINISHED])
not_done = set(fs) - done

if (return_when == FIRST_COMPLETED) and done:
return DoneAndNotDoneFutures(done, not_done)
elif (return_when == FIRST_EXCEPTION) and done:
Expand All @@ -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)

class Future(object):
"""Represents the result of an asynchronous computation."""
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_concurrent_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,14 @@ def test_shutdown_no_wait(self):


class WaitTests:

def test_first_completed(self):
future1 = self.executor.submit(mul, 21, 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Toggle all file notes Toggle all file annotations