aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/concurrent/futures/process.py
diff options
context:
space:
mode:
authorGrzegorz Grzywacz <grzgrzgrz3@gmail.com>2017-09-01 18:54:00 +0200
committerAntoine Pitrou <pitrou@free.fr>2017-09-01 18:54:00 +0200
commit97e1b1c81458d2109b2ffed32ffa1eb643a6c3b9 (patch)
treee87029349aa808857ea5e2d1582f0f9f66f0cfad /Lib/concurrent/futures/process.py
parent16432beadb8eba079c9786cc0c0eaacfd9fd2f7b (diff)
downloadcpython-97e1b1c81458d2109b2ffed32ffa1eb643a6c3b9.tar.gz
cpython-97e1b1c81458d2109b2ffed32ffa1eb643a6c3b9.zip
bpo-27144: concurrent.futures as_complete and map iterators do not keep reference to returned object (#1560)
* bpo-27144: concurrent.futures as_complie and map iterators do not keep reference to returned object * Some nits. Improve wordings in docstrings and comments, and avoid relying on sys.getrefcount() in tests.
Diffstat (limited to 'Lib/concurrent/futures/process.py')
-rw-r--r--Lib/concurrent/futures/process.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py
index 8f1d714193a..03b28ab5d68 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: