]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Simplify concurrent.futures.process code by using itertools.batched() (GH-114221)
authorNewUserHa <32261870+NewUserHa@users.noreply.github.com>
Sat, 27 Jan 2024 08:29:38 +0000 (16:29 +0800)
committerGitHub <noreply@github.com>
Sat, 27 Jan 2024 08:29:38 +0000 (10:29 +0200)
Lib/concurrent/futures/process.py

index ffaffdb8b3d0aad67928d485b9958ad7d1f841cb..ca843e11eeb83dc78008c6812fd2a91f025bbebd 100644 (file)
@@ -190,16 +190,6 @@ class _SafeQueue(Queue):
             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.
 
@@ -847,7 +837,7 @@ class ProcessPoolExecutor(_base.Executor):
             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)