Skip to content

Simplify concurrent.futures.process code by using itertools.batched() #114221

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

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Changes from all commits
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
12 changes: 1 addition & 11 deletions Lib/concurrent/futures/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,6 @@ def _on_queue_feeder_error(self, e, obj):
super()._on_queue_feeder_error(e, obj)


def _get_chunks(*iterables, chunksize):
""" Iterates over zip()ed iterables in chunks. """
it = zip(*iterables)
while True:
chunk = tuple(itertools.islice(it, chunksize))
if not chunk:
return
yield chunk


def _process_chunk(fn, chunk):
""" Processes a chunk of an iterable passed to map.

Expand Down Expand Up @@ -847,7 +837,7 @@ def map(self, fn, *iterables, timeout=None, chunksize=1):
raise ValueError("chunksize must be >= 1.")

results = super().map(partial(_process_chunk, fn),
_get_chunks(*iterables, chunksize=chunksize),
itertools.batched(zip(*iterables), chunksize),
timeout=timeout)
return _chain_from_iterable_of_lists(results)

Expand Down