def shaixuan(i):
lock.acquire()
if '!' in f[i]:
f[i]=''
elif '#' in f[i]:
f[i]=''
else:
pass
result+=f[i]
lock.release()
if __name__ == '__main__':
# 定义一个线程锁
# 注意修改同一个变量的线程要使用同一个锁
lock = threading.Lock()
# 开启多个线程
t_list = []
for i in range(len(f)):
t = threading.Thread(target=shaixuan, args=(i,))
lock = threading.Lock()
t_list.append(t)
t.start()
for t in t_list:
t.join()
with open('data11.txt','w') as t:
t.write(result)
t.close
endtime = time.time()
print ('start:%f' % endime-starttime)