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
  extracting data from a user-completed fillable pdf Perry 2 1,579 Sep-25-2025, 01:49 PM
Last Post: DeaD_EyE
  Multiprocessing Pool Multiple Instances How to Kill by Pool ID sunny9495 0 1,959 Nov-16-2022, 05:57 AM
Last Post: sunny9495
  processes shall be parallel flash77 4 2,685 Sep-20-2022, 11:46 AM
Last Post: DeaD_EyE
  Sharing imported modules with Sub Processes? Stubblemonster 2 3,206 May-02-2022, 06:42 AM
Last Post: Stubblemonster
  Python multiprocessing Pool apply async wait for process to complete sunny9495 6 13,862 Apr-02-2022, 06:31 AM
Last Post: sunny9495
  Killing processes via python Lavina 2 6,052 Aug-04-2021, 06:20 AM
Last Post: warnerarc
  Pool multiprocessing - know current status in loop? korenron 0 2,503 Jul-28-2021, 08:49 AM
Last Post: korenron
  pool mysql error - not catch by try\except? korenron 1 3,559 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  Python - Import file sequence into Media Pool jensenni 1 3,799 Feb-02-2021, 05:11 PM
Last Post: buran
  sharing variables between two processes Kiyoshi767 1 3,181 Nov-07-2020, 04:00 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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