Skip to content

Commit 268927d

Browse files
committed
avoid container
1 parent 7a1ae46 commit 268927d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Lib/concurrent/futures/_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,6 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
621621
# collected independently of the result_iterator closure.
622622
executor_weakref = weakref.ref(self)
623623

624-
# used by the result_iterator to avoid keeping a reference to the result
625-
result = collections.deque(maxlen=1)
626624
# Yield must be hidden in closure so that the futures are submitted
627625
# before the first iterator value is required.
628626
def result_iterator():
@@ -635,16 +633,19 @@ def result_iterator():
635633
if current_timeout is not None:
636634
current_timeout = end_time - time.monotonic()
637635

638-
result.append(_result_or_cancel(fs.pop(), current_timeout))
636+
# wait for the next result
637+
_result_or_cancel(fs[-1], current_timeout)
639638

639+
# buffer next task
640640
if (
641641
buffersize
642642
and (executor := executor_weakref())
643643
and (args := next(zipped_iterables, None))
644644
):
645645
fs.appendleft(executor.submit(fn, *args))
646646

647-
yield result.pop()
647+
# yield the awaited result
648+
yield fs.pop().result()
648649
finally:
649650
for future in fs:
650651
future.cancel()

0 commit comments

Comments
 (0)