def map(self, function, *iterables, **kwargs): """Returns an iterator equivalent to map(function, iterables). *chunksize* controls the size of the chunks the iterable will be broken into before being passed to the function. If None the size will be controlled by the Pool. """ self._check_pool_state() timeout = kwargs.get('timeout') chunksize = kwargs.get('chunksize', 1) if chunksize < 1: raise ValueError("chunksize must be >= 1") futures = [ self.schedule(process_chunk, args=(function, chunk)) for chunk in iter_chunks(chunksize, *iterables) ] map_future = MapFuture(futures) if not futures: map_future.set_result(MapResults(futures)) return map_future def done_map(_): if not map_future.done(): map_future.set_result(MapResults(futures, timeout=timeout)) for future in futures: future.add_done_callback(done_map) setattr(future, 'map_future', map_future) return map_future
def map(self, function, *iterables, **kwargs): """Computes the *function* using arguments from each of the iterables. Stops when the shortest iterable is exhausted. *timeout* is an integer, if expires the task will be terminated and the call to next will raise *TimeoutError*. The *timeout* is applied to each chunk of the iterable. *chunksize* controls the size of the chunks the iterable will be broken into before being passed to the function. A *pebble.ProcessFuture* object is returned. """ self._check_pool_state() timeout = kwargs.get('timeout') chunksize = kwargs.get('chunksize', 1) if chunksize < 1: raise ValueError("chunksize must be >= 1") futures = [ self.schedule(process_chunk, args=(function, chunk), timeout=timeout) for chunk in iter_chunks(chunksize, *iterables) ] map_future = ProcessMapFuture(futures) if not futures: map_future.set_result(MapResults(futures)) return map_future def done_map(_): if not map_future.done(): map_future.set_result(MapResults(futures)) for future in futures: future.add_done_callback(done_map) setattr(future, 'map_future', map_future) return map_future
def done_map(_): if not map_future.done(): map_future.set_result(MapResults(futures))
def done_map(_): if not map_future.done(): map_future.set_result(MapResults(futures, timeout=timeout))