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


Python pool.terminate方法代码示例

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


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

示例1: _close

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def _close(self):
        for pool in self._managed_pools:
            pool.terminate()
        for pool in self._managed_pools:
            pool.join()
        self._aliases.clear()
        self._aliases_per_pool.clear()
        self._managed_pools.clear() 
开发者ID:airware,项目名称:buzzard,代码行数:10,代码来源:_dataset_pools_container.py

示例2: scrape_with_timeout

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def scrape_with_timeout(page):
    pool = NDPool(processes=1)
    async_result = pool.apply_async(scrape_page, (page,))
    result = None
    try:
        result = async_result.get(timeout=600)
        pool.close()
    except TimeoutError:
        logger.info(u'page scrape timed out: {}'.format(page))
        pool.terminate()

    pool.join()
    return result 
开发者ID:ourresearch,项目名称:oadoi,代码行数:15,代码来源:queue_green_oa_scrape.py

示例3: fit_pixel_multiprocess_nonlinear

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def fit_pixel_multiprocess_nonlinear(data, x, param, reg_mat, use_snip=False):
    """
    Multiprocess fit of experiment data.

    Parameters
    ----------
    data : array
        3D data of experiment spectrum
    param : dict
        fitting parameters

    Returns
    -------
    dict :
        fitting values for all the elements
    """

    num_processors_to_use = multiprocessing.cpu_count()
    logger.info('cpu count: {}'.format(num_processors_to_use))
    pool = multiprocessing.Pool(num_processors_to_use)

    # fit_params = lmfit.Parameters()
    # for i in range(reg_mat.shape[1]):
    #     fit_params.add('a'+str(i), value=1.0, min=0, vary=True)

    result_pool = [pool.apply_async(fit_pixel_nonlinear_per_line,
                                    (n, data[n, :, :], x,
                                     param, reg_mat, use_snip))
                   for n in range(data.shape[0])]

    results = []
    for r in result_pool:
        results.append(r.get())

    pool.terminate()
    pool.join()

    return results 
开发者ID:NSLS-II,项目名称:PyXRF,代码行数:40,代码来源:fit_spectrum.py

示例4: roi_sum_multi_files

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def roi_sum_multi_files(dir_path, file_prefix,
                        start_i, end_i, element_dict,
                        interpath='entry/instrument/detector/data'):
    """
    Fitting for multiple files with Multiprocessing.

    Parameters
    -----------
    dir_path : str
    file_prefix : str
    start_i : int
        start id of given file
    end_i: int
        end id of given file
    element_dict : dict
        dict of element with [low, high] bounds as values
    interpath : str
        path inside hdf5 file to fetch the data

    Returns
    -------
    result : list
        fitting result as list of dict
    """
    num_processors_to_use = multiprocessing.cpu_count()
    logger.info('cpu count: {}'.format(num_processors_to_use))
    pool = multiprocessing.Pool(num_processors_to_use)

    result_pool = [pool.apply_async(roi_sum_calculation,
                                    (dir_path, file_prefix,
                                     m, element_dict, interpath))
                   for m in range(start_i, end_i+1)]

    results = []
    for r in result_pool:
        results.append(r.get())

    pool.terminate()
    pool.join()
    return results 
开发者ID:NSLS-II,项目名称:PyXRF,代码行数:42,代码来源:fit_spectrum.py

示例5: finalize

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def finalize(self):
        pool = self._pool

        self._next = None
        self._pool = None
        if pool is not None:
            pool.terminate() 
开发者ID:chainer,项目名称:chainer,代码行数:9,代码来源:multithread_iterator.py

示例6: ScopedPool

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def ScopedPool(*args, **kwargs):
  """Context Manager which returns a multiprocessing.pool instance which
  correctly deals with thrown exceptions.

  *args - Arguments to multiprocessing.pool

  Kwargs:
    kind ('threads', 'procs') - The type of underlying coprocess to use.
    **etc - Arguments to multiprocessing.pool
  """
  if kwargs.pop('kind', None) == 'threads':
    pool = multiprocessing.pool.ThreadPool(*args, **kwargs)
  else:
    orig, orig_args = kwargs.get('initializer'), kwargs.get('initargs', ())
    kwargs['initializer'] = _ScopedPool_initer
    kwargs['initargs'] = orig, orig_args
    pool = multiprocessing.pool.Pool(*args, **kwargs)

  try:
    yield pool
    pool.close()
  except:
    pool.terminate()
    raise
  finally:
    pool.join() 
开发者ID:luci,项目名称:luci-py,代码行数:28,代码来源:git_common.py

示例7: __call__

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def __call__(self, net_lists):
        evaluations = np.zeros(len(net_lists))
        for i in np.arange(0, len(net_lists), self.gpu_num):
            process_num = np.min((i + self.gpu_num, len(net_lists))) - i
            pool = NoDaemonProcessPool(process_num)
            arg_data = [(cnn_eval, net_lists[i+j], j, self.epoch_num, self.dataset,
                         self.verbose, self.imgSize, self.batchsize, self.mask) for j in range(process_num)]
            evaluations[i:i+process_num] = pool.map(arg_wrapper_mp, arg_data)
            pool.terminate()

        return evaluations


# network configurations 
开发者ID:sg-nm,项目名称:Evolutionary-Autoencoders,代码行数:16,代码来源:cgp_config.py

示例8: __call__

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def __call__(self, net_lists):
        evaluations = np.zeros(len(net_lists))
        for i in np.arange(0, len(net_lists), self.gpu_num):
            process_num = np.min((i + self.gpu_num, len(net_lists))) - i
            pool = NoDaemonProcessPool(process_num)
            arg_data = [(cnn_eval, net_lists[i+j], j, self.epoch_num, self.batchsize, self.dataset, self.verbose, self.imgSize) for j in range(process_num)]
            evaluations[i:i+process_num] = pool.map(arg_wrapper_mp, arg_data)
            pool.terminate()

        return evaluations


# network configurations 
开发者ID:sg-nm,项目名称:Evolutionary-Autoencoders,代码行数:15,代码来源:cgp_config.py

示例9: closing_pool

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def closing_pool(pool):
    try:
        with contextlib.closing(pool) as pll:
            yield pll
    except Exception as exc:
        syslog.syslog(syslog.LOG_WARNING,
                      "Terminate pool due to {0}".format(exc))
        pool.terminate()
        raise
    finally:
        pool.join() 
开发者ID:Mirantis,项目名称:ceph-lcm,代码行数:13,代码来源:debug_snapshot.py

示例10: run_calls

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import terminate [as 别名]
def run_calls(fun, list_of_args, extra_args=(), pool_type='processes',
              nb_workers=multiprocessing.cpu_count(), timeout=60, verbose=True,
              initializer=None, initargs=None):
    """
    Run a function several times in parallel with different inputs.

    Args:
        fun: function to be called several times in parallel.
        list_of_args: list of (first positional) arguments passed to fun, one
            per call
        extra_args: tuple containing extra arguments to be passed to fun
            (same value for all calls)
        pool_type: either 'processes' or 'threads'
        nb_workers: number of calls run simultaneously
        timeout: number of seconds allowed per function call
        verbose: either True (show the amount of computed calls) or False
        initializer, initargs (optional): if initializer is not None then each
            worker process will call initializer(*initargs) when it starts

    Return:
        list of outputs
    """
    if pool_type == 'processes':
        pool = multiprocessing.Pool(nb_workers, initializer, initargs)
    elif pool_type == 'threads':
        pool = multiprocessing.pool.ThreadPool(nb_workers)
    else:
        print('ERROR: unknow pool_type "{}"'.format(pool_type))

    results = []
    outputs = []
    if verbose:
        show_progress.counter = 0
        show_progress.total = len(list_of_args)
    for x in list_of_args:
        if type(x) == tuple:
            args = x + extra_args
        else:
            args = (x,) + extra_args
        results.append(pool.apply_async(fun, args=args,
                                        callback=show_progress if verbose else None))

    for r in results:
        try:
            outputs.append(r.get(timeout))
        except KeyboardInterrupt:
            pool.terminate()
            sys.exit(1)

    pool.close()
    pool.join()
    return outputs 
开发者ID:cmla,项目名称:tsd,代码行数:54,代码来源:parallel.py


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