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


Python Pool.wait方法代码示例

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


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

示例1: Pool

# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import wait [as 别名]
class Pool(object):
  '''
  
  '''
  def __init__(self, **pool_kwargs):
  
    try:
      kw = KwargsCheck(MPIPool, pool_kwargs)
      self._pool = MPIPool(**kw)
      self.MPI = True
    except (ImportError, ValueError):
      kw = KwargsCheck(MultiPool, pool_kwargs)
      self._pool = MultiPool(**kw)
      self.MPI = False
    
    if self.MPI:
      if not self._pool.is_master():
        self._pool.wait()
        sys.exit(0)
  
  def map(self, f, x, args = (), kwargs = {}): 
    '''
    
    '''
    if len(args) or len(kwargs):
      w = wrap(f, *args, **kwargs)  
      return self._pool.map(w, x)
    else:
      return self._pool.map(f, x)
  
  def close(self):
    self._pool.close()
    
开发者ID:bmorris3,项目名称:para,代码行数:34,代码来源:wrappers.py

示例2: Pool

# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import wait [as 别名]
class Pool(object):
  '''
  A wrapper around ``Pool`` objects in ``multiprocessing`` and ``mpi4py``. As of now,
  this class has a single method, ``map``, which invokes the corresponding method in
  either the ``multiprocessing`` or ``mpi4py`` pool objects.
  
  '''
  def __init__(self, **pool_kwargs):
  
    try:
      self._pool = MPIPool(**FilterKwargs(MPIPool, pool_kwargs))
      self.MPI = True
    except (ImportError, ValueError):
      self._pool = MultiPool(**FilterKwargs(MultiPool, pool_kwargs))
      self.MPI = False
    
    if self.MPI:
      if not self._pool.is_master():
        
        try:
          self._pool.wait()
        except Exception as e:
          self._pool.kill(e)
          
        sys.exit(0)
  
  def map(self, f, x, args = (), kwargs = {}): 
    '''
    
    '''
    if len(args) or len(kwargs):
      w = Wrap(f, *args, **kwargs)  
      return self._pool.map(w, x)
    else:
      return self._pool.map(f, x)
  
  @property
  def size(self):
    return self._pool.size
  
  def close(self):
    self._pool.close()
    
开发者ID:rodluger,项目名称:para,代码行数:44,代码来源:wrappers.py


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