I am trying to create a variable batch size, to make a subprocess call. I am a bit confused on the best way to have a batch of 5 kick off, wait for all 5 to complete than kick off the next five.
What I have so far is:
batchSize = 5
proccessArray = process.split(",")
processLength = len(proccessArray) - 1
counter1 = 0
for i in range(0, processLength, batchSize):
for x in range(1, batchSize):
d = {}
if counter1 < processLength:
dgclOutput = inputPath + st + "_" + (i + x) + "output"
d["process{0}".format(x)] = subprocess.Popen(proccessArray(i + x) + ">>" + dgclOutput, shell=True, stdout=subprocess.PIPE)
counter1 + 1
else:
break
BatchSize is my number of batches I which to go at a time. Process Array is a listing of commands it needs to call. Process length is the amount of possible commands. Counter is to kick out of the loop when it reaches the max.
So my first loop steps in the amount of the batch size, than an inner loop that creates 5 subpoccesses in a dictionary to kick off.
This code does not work, anyone have an idea how to make it work or a better solution?