I use the below script to spawn multiple python scripts in the server. The argument given to each of the script l is different and varies from 0 to 150.
for i in `seq 0 9`;
do
for j in `seq 0 14`;
do
f=$((i*15))
l=$((j+f))
./script --l ${l} &
done
i=0
for job in `jobs -p`
do
pids[${i}]=${job}
i=$((i+1))
done
for pid in ${pids[*]}; do
wait ${pid}
done
done
The above syntax spawns 15 python scripts and waits for each of the child processes to finish before spawning the subsequent 15. However, the python script takes little time for some values of l and lots of time for other values of l. My problem is that, if for a given set of 15 l values, the script takes very little time for 14 of them and lots of time for one value of l, then the above script waits for the one script to finish before spawning the next 15, which results in many of the cores in the server remaining idle. I was wondering if there is a way to modify the above code to spawn a new child process every time one of them finishes (so that there are 15 child processes running at any given time).
Thanks
multiprocessinglibrary in python? docs.python.org/3/library/multiprocessing.html