diff options
author | Brian Quinlan <brian@sweetapp.com> | 2011-04-08 08:19:33 +1000 |
---|---|---|
committer | Brian Quinlan <brian@sweetapp.com> | 2011-04-08 08:19:33 +1000 |
commit | 05b8830637810257995b9131ce8b7423afa254ef (patch) | |
tree | 6b900160439d584b728ad33788eb85e52b0aafd1 /Lib/concurrent | |
parent | 88adf3eab839d12b7552946b03066c5de136b782 (diff) | |
download | cpython-05b8830637810257995b9131ce8b7423afa254ef.tar.gz |
Issue #11777: Executor.map does not submit futures until iter.next() is called
Diffstat (limited to 'Lib/concurrent')
-rw-r--r-- | Lib/concurrent/futures/_base.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py index 79b91d495f..6cfded3075 100644 --- a/Lib/concurrent/futures/_base.py +++ b/Lib/concurrent/futures/_base.py @@ -536,15 +536,19 @@ class Executor(object): fs = [self.submit(fn, *args) for args in zip(*iterables)] - try: - for future in fs: - if timeout is None: - yield future.result() - else: - yield future.result(end_time - time.time()) - finally: - for future in fs: - future.cancel() + # Yield must be hidden in closure so that the futures are submitted + # before the first iterator value is required. + def result_iterator(): + try: + for future in fs: + if timeout is None: + yield future.result() + else: + yield future.result(end_time - time.time()) + finally: + for future in fs: + future.cancel() + return result_iterator() def shutdown(self, wait=True): """Clean-up the resources associated with the Executor. |