Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
format comments
  • Loading branch information
ebonnal committed Mar 23, 2025
commit f2c5fd0d25feda6dff5d8d6c93ed861288152759
10 changes: 5 additions & 5 deletions Lib/concurrent/futures/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,25 +625,25 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
# before the first iterator value is required.
def result_iterator():
try:
# Reverse so that the next (FIFO) future is on the right
# reverse so that the next (FIFO) future is on the right
fs.reverse()
# Careful not to keep references to futures or results
# careful not to keep references to futures or results
while fs:
# Wait for the next result
# wait for the next result
if timeout is None:
_result_or_cancel(fs[-1])
else:
_result_or_cancel(fs[-1], end_time - time.monotonic())

# Buffer next task
# buffer next task
if (
buffersize
and (executor := executor_weakref())
and (args := next(zipped_iterables, None))
):
fs.appendleft(executor.submit(fn, *args))

# Yield the awaited result
# yield the awaited result
yield fs.pop().result()
Copy link
Copy Markdown
Contributor Author

@ebonnal ebonnal Mar 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be discussed: this could be replaced by a lighter yield fs.pop()._result because the prior call to _result_or_cancel guarantees that at this point the result is available.

finally:
for future in fs:
Expand Down
Loading