I have a directory which contains a list of files that need running. These are pretty computationally heavy tasks so I'm looking for the best way to run multiple files at once.My first function for task submission was:
def copasiSE_batch_run(self):
os.chdir(self.IA_dir) #dir containing files
count=0
for i in glob.glob('*.cps'):
os.system('CopasiSE '+i)
count = count+1
print '\n\n\n {}:\tProfile liklihood for {} has been calcualted'.format(count,i)
This is fine and it works but only uses one process, waits until one file is finished running then runs the next. Since these are independent tasks It would be good if I could get more going at the same time. I then tried:
def copasiSE_batch_run_subprocess(self):
os.chdir(self.IA_dir)
for i in glob.glob('*.cps'):
command='CopasiSE '+i
subprocess.Popen( command)
This also works but gives me the opposite problem. I have 32 files that need running and this function seems to run them all at once so that my computer is basically unusable until it done. What would be the best way to find a good balance between number of running programs at once and having enough computer power left over to do some reasonably low intensive tasks?