diff options
author | Antoine Pitrou <pitrou@free.fr> | 2017-09-01 17:16:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-01 17:16:46 (GMT) |
commit | ea767915f7476c1fe97f7b1a53304d57f105bdd2 (patch) | |
tree | c9945795ded82474153e56aca0560d58cc30ce51 /Lib/concurrent/futures/process.py | |
parent | 98c849a2f32f6727239b4cce38b8f0ff8adeef22 (diff) | |
download | cpython-ea767915f7476c1fe97f7b1a53304d57f105bdd2.zip cpython-ea767915f7476c1fe97f7b1a53304d57f105bdd2.tar.gz cpython-ea767915f7476c1fe97f7b1a53304d57f105bdd2.tar.bz2 |
[3.6] bpo-27144: concurrent.futures as_complete and map iterators do not keep reference to returned object (GH-1560) (#3266)
bpo-27144: concurrent.futures as_complie and map iterators do not keep
reference to returned object
(cherry picked from commit 97e1b1c81458d2109b2ffed32ffa1eb643a6c3b9)
Diffstat (limited to 'Lib/concurrent/futures/process.py')
-rw-r--r-- | Lib/concurrent/futures/process.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py index 8f1d714..03b28ab 100644 --- a/Lib/concurrent/futures/process.py +++ b/Lib/concurrent/futures/process.py @@ -357,6 +357,18 @@ def _check_system_limits(): raise NotImplementedError(_system_limited) +def _chain_from_iterable_of_lists(iterable): + """ + Specialized implementation of itertools.chain.from_iterable. + Each item in *iterable* should be a list. This function is + careful not to keep references to yielded objects. + """ + for element in iterable: + element.reverse() + while element: + yield element.pop() + + class BrokenProcessPool(RuntimeError): """ Raised when a process in a ProcessPoolExecutor terminated abruptly @@ -482,7 +494,7 @@ class ProcessPoolExecutor(_base.Executor): results = super().map(partial(_process_chunk, fn), _get_chunks(*iterables, chunksize=chunksize), timeout=timeout) - return itertools.chain.from_iterable(results) + return _chain_from_iterable_of_lists(results) def shutdown(self, wait=True): with self._shutdown_lock: |