import os import sys import glob import time import threading hdd_root = '/hdd/*' def cmd_run(shell_cmd): os.system(str(shell_cmd)) def main(): surgery_list = glob.glob(hdd_root) for id in surgery_list: if 'lost+found' in id: surgery_list.remove(id) else: pass for id in surgery_list: file_list=glob.glob(id + '/*') for file in file_list: if 'log.txt' in file: f = open(file, 'rt') logs = f.readlines() f.close() if len(logs) == 2: thread_list = [] f = open(file, 'at') r_time = time.ctime(time.time()) f.write('exectue is successfully starts at ' + str(r_time) + '\n') f.close() cmd_list = ['docker run --rm --name extract_1 --gpus '"device=0"' -v /dev:/dev -v /home/mc365/sources:/sources -v /hdd:/hdd ellishuntingmoon/mailsys:0.4 python3 /sources/extract_01.py ' + id + '/ >> /dev/null', 'docker run --rm --name extract_2 --gpus '"device=1"' -v /dev:/dev -v /home/mc365/sources:/sources -v /hdd:/hdd ellishuntingmoon/mailsys:0.4 python3 /sources/extract_02.py ' + id + '/ >> /dev/null'] for index in range(0, len(cmd_list)): thread_list.append(threading.Thread(target=cmd_run,args=cmd_list[index])) thread_list[index].start() f = open(file, 'at') r_time = time.ctime(time.time()) f.write('exectue is successfully ends at ' + str(r_time) + '\n') f.close() else: pass if __name__ == '__main__': while True: main()