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