限制迭代器生成直到确认的值的数量。
项目描述
简介
multiprocessing.pool.ThreadPool 和 multiprocessing.Pool 具有神奇的 imap 和 imap_unordered 方法,允许增量地消耗可迭代对象,并将结果在可用时产生。
这是非常好的,因为它允许处理大于可用内存的输入或结果。
但它有一个重要的缺陷,就是它不会限制未消耗的结果的数量。这导致它无限制地使用内存。
此软件包实现了对可迭代对象的包装,将限制生成直到确认的结果的数量。它允许并发处理一定数量的消息,但不超过这个数量。
使用方法
it = itertools.count() # The input iterable.
it = BoundedIterator(10, it) # Allows concurrent processing of up to 10 values.
results = Pool().imap(str, it) # Will begin consuming `it` and producing results.
time.sleep(5) # No matter what else we do, no more than 10 results will be available.
for res in results: # Consume normally.
print(res)
it.processed() # Acknowledge a value was processed so that a new one can be generated.
开发
设置pre-commit钩子,然后就可以开始了。
pre-commit install --install-hooks
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分发
本发行版没有可用的源代码分发文件。请参阅有关生成分发存档的教程。
编译后的分发
bounded_iterator-1.0.2-py3-none-any.whl (15.4 kB 查看哈希值)