限制迭代器生成的值的数目,直到确认为止。

bounded-iterator的Python项目详细描述


Run StatusCoverage BadgeSupported Python versionsLicense

简介

多处理.pool.threadpool多处理.pool拥有美妙的 imapimap\u无序的方法,允许使用iterable 并将逐步产生结果,因为他们成为可用的。

这是很好的,因为它允许处理大于可用的输入或结果 记忆。

它有一个重要的缺陷,那就是它不限制结果的数量 没有被消耗掉。这会导致它不受限制地使用内存。

这个包在iterable上实现了一个包装器,它将限制 产生的结果,直到他们被承认。它允许 要同时处理的消息,但不能超过此值。

用法

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.forresinresults:# Consume normally.print(res)it.processed()# Acknowledge a value was processed so that a new one can be generated.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带有嵌套JAR的java RCP ClassNotFoundException   java在输入框中设置默认值,crud应用程序使用spring   java如何在Heroku中使用fs创建新文件   java将JPanel放在JFrame中   java这个正则表达式会匹配“i.imgur.com/xxx”吗?   java在片段内创建RecylerView,而无需在Android中设置片段   Android上Groovy导致java错误的双精度浮点精度损失   swing Java查找JFrame属于JPanel的内容   java Spring junit自连线自定义类本身必须有构造函数吗?   java textswitcher支持前面的文本   从Android客户端到JAXRS的java Post自定义对象   java如何检索JSON数据并使用MPAndroidChart绘制折线图,以及在安卓上的改进   拒绝用户“root”@“localhost”的java c3p0访问(使用密码“是”)   使用Selenium Webdriver自动化ExtJS应用程序时java面临的问题