Try running your original script in a separate process from the script that does the looping, passing the directory to process to the original script each loop:#Master script to loop
def runcmd(cmd, format='s'):
import subprocess
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
stdout,stderr=proc.communicate()
exit_code=proc.wait()
return exit_code,stdout,stderr
for dir in <list of directories>:
cmd ='%s %s %s' % (<path to python>, <path to your script>, dir)
exit_code,stdout,stderr = runcmd(cmd)