本文整理汇总了Python中multiprocessing.pool.Pool.starmap方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.starmap方法的具体用法?Python Pool.starmap怎么用?Python Pool.starmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.pool.Pool
的用法示例。
在下文中一共展示了Pool.starmap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import starmap [as 别名]
def update(self, export='csv', path='out'):
stock_codes = []
for file in os.listdir(os.path.join(path, 'raw_data')):
if not file.endswith('csv'):
continue
stock_code = file[:-4]
stock_codes.append(stock_code)
pool = Pool(10)
params = [(code, path) for code in stock_codes]
if export.lower() in ['csv']:
pool.starmap(self.update_single_code, params)
示例2: _process
# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import starmap [as 别名]
def _process(cls, spectrum, filter_spectrum, *args):
"""This private class method process spectrum with a given filter
and parameters.
.. note:: If no filter spectrum is provided, then it passes None as
filter spectrum point to all processes.
This method uses multiprocessing.
"""
if filter_spectrum:
resampled_filter_spectrum = filter_spectrum.resample(spectrum)
resampled_filter_lines = resampled_filter_spectrum.lines
else:
resampled_filter_lines = repeat(None, len(spectrum.lines))
data = zip(spectrum.lines, resampled_filter_lines, repeat(args))
p = Pool()
y_values = p.starmap(cls._func, data)
p.close()
p.join()
lines = zip(spectrum.x_values, y_values)
return type(spectrum)(lines, interpolation=spectrum.interpolation)
示例3: Article
# 需要导入模块: from multiprocessing.pool import Pool [as 别名]
# 或者: from multiprocessing.pool.Pool import starmap [as 别名]
article = Article(URL_PREFIX + "/wiki/Special:Export/Template:Periodic_table")
categories = []
params = []
for row in article.get_table("table 1"):
for key, value in row.items():
segments = [segment.strip() for segment in value.split(";")]
if len(segments) >= 7:
if segments[5].lower() not in categories:
categories.append(segments[5].lower())
params.append(
(
segments[1],
segments[7].replace(" ", "_") if len(segments) > 7 else segments[1].capitalize(),
ionization_energies,
element_names,
categories.index(segments[5].lower()),
)
)
pool = Pool(processes=multiprocessing.cpu_count() * 2)
json_data = pool.starmap(parse, params)
pool.close()
pool.join()
# Save
with open(OUTPUT_JSON, "w+") as outfile:
json.dump(json_data, outfile, sort_keys=True, indent=4, ensure_ascii=False)