| | | | | | | from time import time | | import threading | | | | loops = ['1.txt','2.txt'] | | | | | | class threadFunc(threading.Thread): | | def __init__(self,func,args,name=''): | | threading.Thread.__init__(self) | | self.func = func | | self.args = args | | self.name = name | | def run(self): | | self.func(*self.args) | | | | def loop(name): | | with open(name,'r') as f: | | for line in f: | | if '\n' in line: | | print (name,' :',line,end='') | | else: | | print (name,' :',line) | | | | def main(): | | print('starting at:',time()) | | | | threadkey = [] | | nloops = range(len(loops)) | | | | for i in nloops: | | | | | | t = threadFunc(loop,(loops[i],),loop.__name__) | | threadkey.append(t) | | | | | | for i in nloops: | | threadkey[i].start() | | | | for i in nloops: | | threadkey[i].join() | | | | print('All Done at:',time()) | | | | if __name__ == '__main__': | | main()COPY |
| starting at: 1590562220.892479 | | 1.txt : 1005495524----a111111 | | 1.txt : 1005495524----abc123 | | 2.txt : 1111qqqq1111---a111111 | | 1.txt : 1005495524----aini1314 | | 2.txt : 1111qqqq1111---abc123 | | 1.txt : 1005495524----iloveyou | | 2.txt : 1111qqqq1111---aini1314 | | 1.txt : 1005495524----q1w2e3r4 | | 2.txt : 111qqq111---a111111 | | 1.txt : 1005495524----qq123123 | | 2.txt : 111qqq111---abc123 | | 2.txt : 111qqq111---aini1314 | | All Done at: 1590562220.892479 | | | | 请按任意键继续. . .COPY |
|