-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_all.py
executable file
·58 lines (49 loc) · 1.22 KB
/
run_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File : run_all.py
@Time : 2019/11/05 14:16:34
@Author : rachpt
@Version : 0.2
@Contact : [email protected]
@Desc : 批量提交计算任务
'''
import os
import threading
from time import sleep
PWD = '/srv/space/rigged/jobs/电离率'
cpus = 7
Prog = 'xe'
INCLUDE = '/srv/space/rigged/include.sh'
# ------------------------------------------ #
lst = os.listdir(PWD)
total = len(lst)
def call(dr):
print('start task: ' + dr)
_pwd = 'cd "' + PWD + '/' + dr + '" && source ' + INCLUDE + ' >/dev/null && '
cmd = _pwd + Prog+'1 &>/dev/null && '+Prog+'2 &>/dev/null'
os.system(cmd)
# print(cmd)
print('end task: ' + dr)
threads = {}
n = 0
for i in range(total):
threads[i] = threading.Thread(target=call, args=(lst[n], ))
n += 1
if __name__ == '__main__':
n = 0
while True:
if threading.active_count() <= cpus:
threads[n].start()
n += 1
if n >= total:
break
else:
sleep(10)
print("All submitted! Waitting last calc.")
while True:
if threading.active_count() == 1:
print("Done!")
break
else:
sleep(10)