I have a text file which consist of list of dates. I want to pass every date to a shell script as a parameter and run the script for all the specified date from the file.
I want to execute this task in parallel using python. Since the script has complex logic and to monitor the execution I want to run 5 instances at a time. As soon as the scripts are completed python has to start new thread.
import threading
import time
class mythread(threading.Thread):
def __init__(self, i):
threading.Thread.__init__(self)
self.h = i
# Script will call the function
def run(self):
time.sleep(1)
print("Value send ", self.h)
f = open('C:\Senthil\SenStudy\Python\Date.txt').readlines()
num = threading.activeCount()
for i in f:
print("Active threads are ", num)
time.sleep(1)
if threading.activeCount() <= 5:
thread1 = mythread(i)
thread1.start()
else:
print("Number of Threads are More than 5 .. going to sleep state for 1 mint ...")
time.sleep(1)
I tried using threading.activeCount()
to get the number of threads running, but from the beginning it says number of threads are 30 (which is number of all date entries in the file).