Python Forum
How to restart the processes in the pool after the pool got completed
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to restart the processes in the pool after the pool got completed
#1
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

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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiprocessing Pool Multiple Instances How to Kill by Pool ID sunny9495 0 1,432 Nov-16-2022, 05:57 AM
Last Post: sunny9495
  processes shall be parallel flash77 4 1,962 Sep-20-2022, 11:46 AM
Last Post: DeaD_EyE
  Python multiprocessing Pool apply async wait for process to complete sunny9495 6 11,515 Apr-02-2022, 06:31 AM
Last Post: sunny9495
  Killing processes via python Lavina 2 4,182 Aug-04-2021, 06:20 AM
Last Post: warnerarc
  Pool multiprocessing - know current status in loop? korenron 0 2,116 Jul-28-2021, 08:49 AM
Last Post: korenron
  pool mysql error - not catch by try\except? korenron 1 2,861 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  Python - Import file sequence into Media Pool jensenni 1 2,913 Feb-02-2021, 05:11 PM
Last Post: buran
  sharing variables between two processes Kiyoshi767 1 2,563 Nov-07-2020, 04:00 AM
Last Post: ndc85430
  2 or more processes on the write end of the same pipe Skaperen 4 5,827 Sep-27-2020, 06:41 PM
Last Post: Skaperen
  How a Mac OS software can restart itself with admin permission in Python 3.7? Formationgrowthhacking 0 2,380 Sep-03-2020, 05:29 PM
Last Post: Formationgrowthhacking

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020