当前位置: 首页>>代码示例>>Python>>正文


Python Pool._get_tasks方法代码示例

本文整理汇总了Python中multiprocessing.pool.Pool._get_tasks方法的典型用法代码示例。如果您正苦于以下问题:Python Pool._get_tasks方法的具体用法?Python Pool._get_tasks怎么用?Python Pool._get_tasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.pool.Pool的用法示例。


在下文中一共展示了Pool._get_tasks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: imap_unordered

# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import _get_tasks [as 别名]
 def imap_unordered(self, func, iterable, second_argument, chunksize=1):
     '''
     Like `imap()` method but ordering of results is arbitrary
     '''
     assert self._state == RUN
     if chunksize == 1:
         result = IMapUnorderedIterator(self._cache)
         self._taskqueue.put((((result._job, i, func, (x, second_argument), {})
                             for i, x in enumerate(iterable)), result._set_length))
         return result
     else:
         assert chunksize > 1
         task_batches = Pool._get_tasks(func, iterable, chunksize)
         result = IMapUnorderedIterator(self._cache)
         self._taskqueue.put((((result._job, i, mapstar, (x, second_argument), {})
                             for i, x in enumerate(task_batches)), result._set_length))
         return (item for chunk in result for item in chunk)
开发者ID:inspirehep,项目名称:inspire-next,代码行数:19,代码来源:cli.py

示例2: imap

# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import _get_tasks [as 别名]
 def imap(self, func, iterable, chunksize=1):
     '''
     Equivalent of `itertools.imap()` -- can be MUCH slower than `Pool.map()`
     '''
     assert self._state == RUN
     if chunksize == 1:
         result = IMapIterator(self._cache)
         self._taskqueue.put((((result._job, i, func, (x,), {})
                               for i, x in enumerate(iterable)), result._set_length))
         return result
     else:
         assert chunksize > 1
         task_batches = Pool._get_tasks(func, iterable, chunksize)
         result = IMapIterator(self._cache)
         self._taskqueue.put((((result._job, i, mapstar, (x,), {})
                               for i, x in enumerate(task_batches)), result._set_length))
         return (item for chunk in result for item in chunk)
开发者ID:aelaguiz,项目名称:pyvotune,代码行数:19,代码来源:timeout_pool.py

示例3: map_async

# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import _get_tasks [as 别名]
    def map_async(self, func, iterable, chunksize=None, callback=None):
        '''
        Asynchronous equivalent of `map()` builtin
        '''
        assert self._state == RUN
        if not hasattr(iterable, '__len__'):
            iterable = list(iterable)

        if chunksize is None:
            chunksize, extra = divmod(len(iterable), len(self._pool) * 4)
            if extra:
                chunksize += 1
        if len(iterable) == 0:
            chunksize = 0

        task_batches = Pool._get_tasks(func, iterable, chunksize)
        result = MapResult(self._cache, chunksize, len(iterable), callback)
        self._taskqueue.put((((result._job, i, mapstar, (x,), {})
                              for i, x in enumerate(task_batches)), None))
        return result
开发者ID:aelaguiz,项目名称:pyvotune,代码行数:22,代码来源:timeout_pool.py


注:本文中的multiprocessing.pool.Pool._get_tasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。