Skip to content

bpo-29842: Make Executor.map less eager so it handles large/unbounded… #707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
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
Fix behavior to follow test_free_reference requirements (generator ho…
…lds no reference to result at the moment it yields

Reduce line lengths to PEP8 limits
  • Loading branch information
MojoVampire committed May 6, 2019
commit 3c38fabdfe9d625064625b4fb84aa41d59bf250d
9 changes: 5 additions & 4 deletions Lib/concurrent/futures/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,9 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, prefetch=None):
raise ValueError("prefetch count may not be negative")

argsiter = zip(*iterables)
initialargs = itertools.islice(argsiter, self._max_workers + prefetch)

fs = collections.deque(self.submit(fn, *args) for args in itertools.islice(argsiter, self._max_workers + prefetch))
fs = collections.deque(self.submit(fn, *args) for args in initialargs)

# Yield must be hidden in closure so that the futures are submitted
# before the first iterator value is required.
Expand All @@ -611,9 +612,9 @@ def result_iterator():
try:
while fs:
if timeout is None:
res = fs[0].result()
res = [fs[0].result()]
else:
res = fs[0].result(end_time - time.monotonic())
res = [fs[0].result(end_time - time.monotonic())]

# Got a result, future needn't be cancelled
del fs[0]
Expand All @@ -628,7 +629,7 @@ def result_iterator():
else:
fs.append(self.submit(fn, *args))

yield res
yield res.pop()
finally:
for future in fs:
future.cancel()
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy