本文整理汇总了Python中multiprocessing.pool.Pool.is_master方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.is_master方法的具体用法?Python Pool.is_master怎么用?Python Pool.is_master使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.pool.Pool
的用法示例。
在下文中一共展示了Pool.is_master方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Pool
# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import is_master [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()
示例2: Pool
# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import is_master [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()