diff -r 8fe59931b64d Lib/concurrent/futures/_base.py --- a/Lib/concurrent/futures/_base.py Thu Jan 23 11:25:48 2014 +0100 +++ b/Lib/concurrent/futures/_base.py Thu Jan 23 14:39:29 2014 +0100 @@ -190,16 +190,18 @@ def as_completed(fs, timeout=None): if timeout is not None: end_time = timeout + time.time() - with _AcquireFutures(fs): - finished = set( - f for f in fs - if f._state in [CANCELLED_AND_NOTIFIED, FINISHED]) - pending = set(fs) - finished - waiter = _create_and_install_waiters(fs, _AS_COMPLETED) + waiter = _AsCompletedWaiter() + pending = set() + for f in fs: + with f._condition: + if f._state in [CANCELLED_AND_NOTIFIED, FINISHED]: + yield f + else: + pending.add(f) + f._waiters.append(waiter) + installed_waiters = frozenset(pending) try: - yield from finished - while pending: if timeout is None: wait_timeout = None @@ -222,8 +224,9 @@ def as_completed(fs, timeout=None): pending.remove(future) finally: - for f in fs: - f._waiters.remove(waiter) + for f in installed_waiters: + with f._condition: + f._waiters.remove(waiter) DoneAndNotDoneFutures = collections.namedtuple( 'DoneAndNotDoneFutures', 'done not_done')