Returns an iterator equivalent to map(fn, iter). Args: fn: A callable that will take as many arguments as there are passed iterables. timeout: The maximum number of seconds to wait. If None, then there is no limit on the wait time.
(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None)
| 833 | submit.__doc__ = _base.Executor.submit.__doc__ |
| 834 | |
| 835 | def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None): |
| 836 | """Returns an iterator equivalent to map(fn, iter). |
| 837 | |
| 838 | Args: |
| 839 | fn: A callable that will take as many arguments as there are |
| 840 | passed iterables. |
| 841 | timeout: The maximum number of seconds to wait. If None, then there |
| 842 | is no limit on the wait time. |
| 843 | chunksize: If greater than one, the iterables will be chopped into |
| 844 | chunks of size chunksize and submitted to the process pool. |
| 845 | If set to one, the items in the list will be sent one at a time. |
| 846 | buffersize: The number of submitted tasks whose results have not |
| 847 | yet been yielded. If the buffer is full, iteration over the |
| 848 | iterables pauses until a result is yielded from the buffer. |
| 849 | If None, all input elements are eagerly collected, and a task is |
| 850 | submitted for each. |
| 851 | |
| 852 | Returns: |
| 853 | An iterator equivalent to: map(func, *iterables) but the calls may |
| 854 | be evaluated out-of-order. |
| 855 | |
| 856 | Raises: |
| 857 | TimeoutError: If the entire result iterator could not be generated |
| 858 | before the given timeout. |
| 859 | Exception: If fn(*args) raises for any values. |
| 860 | """ |
| 861 | if chunksize < 1: |
| 862 | raise ValueError("chunksize must be >= 1.") |
| 863 | |
| 864 | results = super().map(partial(_process_chunk, fn), |
| 865 | itertools.batched(zip(*iterables), chunksize), |
| 866 | timeout=timeout, |
| 867 | buffersize=buffersize) |
| 868 | return _chain_from_iterable_of_lists(results) |
| 869 | |
| 870 | def shutdown(self, wait=True, *, cancel_futures=False): |
| 871 | with self._shutdown_lock: |