def load_files_parallel(feature_files, load_function, processes, **kwargs):
"""
Function for loading feature files in parallel.
:param feature_files: The collection of files to load.
:param load_function: The function used to load the objects.
:param processes: The number of processes to use for loading the feature files.
:param kwargs: Keyword arguments which will be sent to the load function.
:return: A list of loaded feature data frames or numpy arrays.
"""
logging.info("Reading files in parallel")
pool = multiprocessing.Pool(processes)
try:
#Create a partial function with the keyword arguments set. This is done since the parallel map from
# multiprocessing expects a function which takes a single argument.
partial_load_and_pivot = partial(load_function, **kwargs)
segment_frames = pool.map(partial_load_and_pivot, feature_files)
finally:
pool.close()
return segment_frames
评论列表
文章目录