- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcess.py
More file actions
Latest commit
69 lines (64 loc) · 2.47 KB
/
Copy pathProcess.py
File metadata and controls
69 lines (64 loc) · 2.47 KB
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
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
"""注意:
1,含有'.for'文件的文件夹只能含有一个'.for'文件
2,use 'ctrl+c' to stop.
@author: 409200093@qq.com
"""
print(__doc__)
importos
importsubprocessassp
frommultiprocessingimportcpu_count,Pool
importmath
importpsutilasps
importtime
defdone(path_bonus):
start=time.time()
idir,ifile=os.path.split(path_bonus)
os.chdir(idir)
foriinos.listdir(idir):
ifos.path.splitext(i)[1] in ['.out','.dat']:
os.remove(i)
a=sp.call('gfortran %s'%path_bonus,shell=True)
if'a.out'inos.listdir(os.getcwd()) anda==0:
print('Pid is %d. Address is %s is starting!'%(os.getpid(),path_bonus))
time.sleep(10.0)
a=sp.call('./a.out',shell=True)
print('Pid is %d. Address is %s has done! last %.3f hours'%(os.getpid(),path_bonus,(time.time()-start)/3600.0))
return ('Pid is %d. Address is %s has done! last %.3f hours'%(os.getpid(),path_bonus,(time.time()-start)/3600.0))
else:
print('Pid is %d. Address is %s is wrong!! last %.3f seconds'%(os.getpid(),path_bonus,(time.time()-start)))
time.sleep(10.0)
return ('Pid is %d. Address is %s is wrong!! last %.3f seconds'%(os.getpid(),path_bonus,(time.time()-start)))
path_dir=input(r'please input dir addres:')
for_file=[]
defget_for(path_dir):
forroot,dirs,filesinos.walk(path_dir):
forifileinfiles:
for_file.append(os.path.join(root,ifile))
get_for(path_dir)
path_omf=[iforiinfor_fileifos.path.splitext(os.path.split(i)[1])[1]=='.for']
assertlen(path_omf)>0,"输入包含'.for'的文件夹"
if__name__=='__main__':
min_cpu=math.ceil(cpu_count()*0.95-sum(ps.cpu_percent(percpu=True))/100)-1
lensub=min(min_cpu,len(path_omf))
assertlensub>=1, 'None cpu is avaliable,please try again at another time!'
print('Pid is %d'%os.getpid())
print('%d cpus is available,%d subprocess needed ,so %d subprocess is created'%(min_cpu,len(path_omf),lensub))
ifinput('"ENTER" to continue,others to exit: ')=='':
pass
else:
raiseException('Stopped by user!')
time.sleep(1.0)
pool=Pool(lensub)
result=[]
foriinpath_omf:
c=pool.apply_async(done,args=(i,))
result.append(c)
pool.close()
pool.join()
forresinresult:
print(res.get())
os.chdir(path_dir)
withopen('done.txt','w') asf:
f.write('All in %s is over!'%path_dir)
print('All in %s is over!'%path_dir)