I'm using python's multiprocessing
module for parallelising and processing my data. Before I close this process pool, I want to execute a function for each of the sub-processes that are spawned. How can I achieve this?
eg, below is a sample code:
from multiprocessing import Pool
def publish_metadata():
print(str(metadata))
metadata = []
def process_row(row={}):
global metadata
metadata.append("something")
# process the data
if __name__ == "__main__":
pl = [////] # list to process data, each row is a dict
pool = Pool(processes=10)
pool.map(process_row, pl)
pool.close()
pool.join()
I want to run this function publish_metadata
which will contain sub-process specific metadata, before I merge and close process pool (pool.close
). How can I achieve that?