slinkie.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:slinkie 作者: segfaultsourcery 项目源码 文件源码
def parallelize(self, fn, number_of_threads=None):
        """
        Parallelize a function call. Number of threads defaults to your cpu count + 1.
        """

        number_of_threads = number_of_threads or (cpu_count() + 1)

        def _inner():
            with ThreadPoolExecutor(number_of_threads) as tpe:
                tasks = [tpe.submit(fn, item) for item in self._items]
                for future in as_completed(tasks):
                    try:
                        yield future.result()
                    except Exception as exception:
                        yield exception

        return Slinkie(_inner())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号