mirror of
https://github.com/python/cpython.git
synced 2025-11-11 14:44:57 +00:00
Issue #11777: Executor.map does not submit futures until iter.next() is called
This commit is contained in:
parent
0df80926c9
commit
f007876bd6
2 changed files with 22 additions and 10 deletions
|
|
@ -536,6 +536,9 @@ class Executor(object):
|
||||||
|
|
||||||
fs = [self.submit(fn, *args) for args in zip(*iterables)]
|
fs = [self.submit(fn, *args) for args in zip(*iterables)]
|
||||||
|
|
||||||
|
# Yield must be hidden in closure so that the futures are submitted
|
||||||
|
# before the first iterator value is required.
|
||||||
|
def result_iterator():
|
||||||
try:
|
try:
|
||||||
for future in fs:
|
for future in fs:
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
|
|
@ -545,6 +548,7 @@ class Executor(object):
|
||||||
finally:
|
finally:
|
||||||
for future in fs:
|
for future in fs:
|
||||||
future.cancel()
|
future.cancel()
|
||||||
|
return result_iterator()
|
||||||
|
|
||||||
def shutdown(self, wait=True):
|
def shutdown(self, wait=True):
|
||||||
"""Clean-up the resources associated with the Executor.
|
"""Clean-up the resources associated with the Executor.
|
||||||
|
|
|
||||||
|
|
@ -369,7 +369,15 @@ class ExecutorTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest):
|
class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest):
|
||||||
pass
|
def test_map_submits_without_iteration(self):
|
||||||
|
"""Tests verifying issue 11777."""
|
||||||
|
finished = []
|
||||||
|
def record_finished(n):
|
||||||
|
finished.append(n)
|
||||||
|
|
||||||
|
self.executor.map(record_finished, range(10))
|
||||||
|
self.executor.shutdown(wait=True)
|
||||||
|
self.assertCountEqual(finished, range(10))
|
||||||
|
|
||||||
|
|
||||||
class ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest):
|
class ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue