cutcutcodec.core.opti.parallel.buffer.starmap

cutcutcodec.core.opti.parallel.buffer.starmap(func: callable, args: Iterable, maxsize: Integral = 0)[source]

Like multiprocessing.pool.ThreadPool.map but with limited buffer and stared args.

Parameters

funccallable

The function to evaluate in an over thread.

argsiterable

The parameters to give a the function.

maxsizeint, default=max(2, os.cpu_count()//2)

The size of the buffer.

Notes

  • Contrary to multiprocessing functions, args is iterated in the main thread.

  • If an exception is raised in one of the threads, it is propagated to this function.

Examples

>>> import itertools
>>> from cutcutcodec.core.opti.parallel.buffer import starmap
>>> def foo(x, y):
...     return x + y
...
>>> list(starmap(foo, itertools.product(["a", "b", "c"], ["1", "2", "3"])))
['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']
>>>