May-27-2018, 02:18 PM
Hi,
I had a python script which runs the processes in parallel in a pool of 3.
Is there any way to restart these process automatically after the pool of processes got completed?
Please help
I had a python script which runs the processes in parallel in a pool of 3.
Is there any way to restart these process automatically after the pool of processes got completed?
Please help
from multiprocessing import Pool import glob import os import csv from threading import Thread from multiprocessing import Pool as ThreadPool import time items = ['ACM','ACX','AW','BC','XU0', 'DRM', 'DHD', 'CR', 'GSK', 'DMS', 'BLS'] work = (["A", 5], ["B", 5], ["C", 5], ["D", 5],["E", 5], ["F", 5], ["G", 5], ["H", 5]) def work_log(work_data): print(" Process %s waiting %s seconds" % (work_data[0], work_data[1])) time.sleep(int(work_data[1])) print(" Process %s Finished." % work_data[0]) items = ['ACM','ACX','AW','BC','XU0', 'DRM', 'DHD', 'CR', 'GSK', 'DMS', 'BLS'] for item in items: try: print item except: print('error with pattern') def pool_handler(): p = Pool(3) p.map(work_log, work) if __name__ == '__main__': pool_handler()Output:[root@edgenode]# python d4.py Process A waiting 5 seconds Process B waiting 5 seconds Process C waiting 5 seconds Process A Finished. ACM ACX AW BC XU0 DRM DHD CR GSK DMS BLS Process D waiting 5 seconds Process B Finished. Process C Finished. ACM ACM ACX ACX AW AW BC BC XU0 XU0 DRM DRM DHD DHD CR CR GSK GSK DMS DMS BLS BLS Process E waiting 5 seconds Process F waiting 5 seconds Process D Finished. ACM ACX AW BC XU0 DRM DHD CR GSK DMS BLS Process G waiting 5 seconds Process E Finished. ACM ACX AW BC XU0 DRM DHD CR GSK DMS BLS Process H waiting 5 seconds Process F Finished. ACM ACX AW BC XU0 DRM DHD CR GSK DMS BLS Process G Finished. ACM ACX AW BC XU0 DRM DHD CR GSK DMS BLS Process H Finished. ACM ACX AW BC XU0 DRM DHD CR GSK DMS BLS 