mesaport.ProjectOps.istarmap

 1# istarmap.py for Python 3.8+
 2import multiprocessing.pool as mpp
 3
 4
 5def istarmap(self, func, iterable, chunksize=1):
 6    """
 7    starmap-version of imap
 8
 9    Parameters
10    ----------
11    func : callable
12        The function to apply to the items of the iterable.
13    iterable : iterable
14        The iterable to apply the function to.
15    chunksize : int, optional
16        The number of items to send to the worker processes at once.
17        Default is 1.
18
19    Returns
20    -------
21    generator
22        A generator that yields the results of applying the function to
23        the items of the iterable.
24
25    Raises
26    ------
27    ValueError
28        If chunksize is less than 1.
29
30    Notes
31    -----
32    This method is similar to the built-in `itertools.starmap`, but
33    uses a pool of worker processes to apply the function in parallel.
34
35    """
36    self._check_running()
37    if chunksize < 1:
38        raise ValueError(
39            "Chunksize must be 1+, not {0:n}".format(
40                chunksize))
41
42    task_batches = mpp.Pool._get_tasks(func, iterable, chunksize)
43    result = mpp.IMapIterator(self)
44    self._taskqueue.put(
45        (
46            self._guarded_task_generation(result._job,
47                                          mpp.starmapstar,
48                                          task_batches),
49            result._set_length
50        ))
51    return (item for chunk in result for item in chunk)
52
53
54mpp.Pool.istarmap = istarmap
def istarmap(self, func, iterable, chunksize=1):
 6def istarmap(self, func, iterable, chunksize=1):
 7    """
 8    starmap-version of imap
 9
10    Parameters
11    ----------
12    func : callable
13        The function to apply to the items of the iterable.
14    iterable : iterable
15        The iterable to apply the function to.
16    chunksize : int, optional
17        The number of items to send to the worker processes at once.
18        Default is 1.
19
20    Returns
21    -------
22    generator
23        A generator that yields the results of applying the function to
24        the items of the iterable.
25
26    Raises
27    ------
28    ValueError
29        If chunksize is less than 1.
30
31    Notes
32    -----
33    This method is similar to the built-in `itertools.starmap`, but
34    uses a pool of worker processes to apply the function in parallel.
35
36    """
37    self._check_running()
38    if chunksize < 1:
39        raise ValueError(
40            "Chunksize must be 1+, not {0:n}".format(
41                chunksize))
42
43    task_batches = mpp.Pool._get_tasks(func, iterable, chunksize)
44    result = mpp.IMapIterator(self)
45    self._taskqueue.put(
46        (
47            self._guarded_task_generation(result._job,
48                                          mpp.starmapstar,
49                                          task_batches),
50            result._set_length
51        ))
52    return (item for chunk in result for item in chunk)

starmap-version of imap

Parameters

func : callable The function to apply to the items of the iterable. iterable : iterable The iterable to apply the function to. chunksize : int, optional The number of items to send to the worker processes at once. Default is 1.

Returns

generator A generator that yields the results of applying the function to the items of the iterable.

Raises

ValueError If chunksize is less than 1.

Notes

This method is similar to the built-in itertools.starmap, but uses a pool of worker processes to apply the function in parallel.