cutcutcodec.core.opti.parallel.buffer.imap

cutcutcodec.core.opti.parallel.buffer.imap(func: Callable, args: Iterable, maxsize: int | None = None)[source]

Do same as multiprocessing.pool.ThreadPool.imap but with a limited output buffer.

Parameters

funccallable

The function to evaluate in an over thread.

argsiterable

The parameters to give a the function.

maxsizeint, default=os.cpu_count()

The size of the buffer.

Examples

>>> from cutcutcodec.core.opti.parallel.buffer import imap
>>> for _ in imap(print, range(4), maxsize=2):
...     print("hello")
...
0
1
hello
2
hello
3
hello
hello
>>>